-
Notifications
You must be signed in to change notification settings - Fork 116
Dev.Front Template API.zh_cn
asset loadblocksconfigdescapeformheadTitleheadMetai18nThemei18nModulenavpaginationControltemplatetemplateComponenturlwidget
提醒:源码文件夹在lib/pi/View/Helper/
$this->assetModule('css/front.css') //返回当前模块下的静态文件路径
$this->assetTheme('css/style.css') //返回当前主题下的静态文件路径
$this->assetModule('css/front.css', 'system') //返回’system‘模块下的静态文件路径
$this->css($this->assetModule('css/front.css')) //加载css
$this->css($this->assetModule('css/front.css'), 'append'); //默认append模式
$this->css($this->assetTheme('css/style.css'), 'prepend'); //引入到前面
$this->css(array()); //同时引入多个
$this->js() //与css同理
<!-- 框架引用 -->
$this->jQuery(); //引入jQuery
$this->jQuery('extension/fileupload.js'); //引入jQuery fileupload.js
$this->Backbone(); //引入 underscore.js backbone.js
$this->bootstrap('css/font-awesome.css'); //加载bootstrap.min.css font-awesome.css
$this->bootstrap(array(
));
$this->bootstrap(array(
), false); //不加载bootstrap.min.css
<!-- 页面底部引入js文件 -->
$this->footScript()->appendFile('file1.js')->appendFile('file2.js');
<!-- 区块脚本 -->
<?php $this->footScript()->captureStart(); ?>
alert('多次引用,但是我只会被加载一次');
<?php $this->footScript()->captureTo('multiple'); ?>
<!-- 页面底部脚本 -->
$script = "$(function() {
$('#da-slider').cslider({
autoplay : true,
});
});";
$this->footScript()->appendScript($script);
<!-- ie条件引用 -->
$this->css(array(
$this->assetTheme('css/style.css'),
$this->assetTheme('css/ie6.css') => array(
'conditional' => 'IE 6', // lt IE 8
),
));
读出一个页面8个区域的所有区块。一般出现在{theme name}/template/layout-front.phtml。然后引入到页面中去。
$blocks = $this->blocks(); // d($blocks);
这个方法能能操作var/config目录下的文件.
name
配置名称。
domain
配置位置,默认值,general。
根据名字返回的数据就是config表里category => general,module => system,如果没有传参数name,则返回Pi\Application\Config处理器,帮助你操作配置数据。
- 返回
var/config/engine.php里面的数据 - 返回
config里面的数据
Pi::config('theme')
Pi::config('environment')
Pi::config('charset')
Pi::config('keywords', 'meta')
....
在页面footer处有个debug,点开就能看见调试的变量
d($var);
过滤html代码
$this->escape($value);
<?php
$form->setAttribute('class', 'form-horizontal');
$form->setAttributes(array(
));
$element = $form->get('username');
$element->getMessages(); //获取表单元素错误信息
$element->getOption('label'); //获取label
$this->formElement($element); //输出元素
$this->formElementErrors($element) //输出元素错误信息
?>
//输出一个bootstrap样式的表单元素
<?php
$form->setAttribute('class', 'form-horizontal');
echo $this->form()->openTag($form);
$this->FormElementErrors()->setMessageOpenFormat('<span class="help-inline">')->setMessageCloseString('</span>');
?>
<?php
$element = $form->get('username'); //输出一个bootstrap样式的表单元素
echo sprintf('<div class="control-group%s"><label class="control-label">%s</label><div class="controls">%s%s</div></div>',
$element->getMessages() ? ' error' : '',
$element->getOption('label'),
$this->formElement($element),
$this->formElementErrors($element));
?>
设置页面title
$this->headTitle('Zend Framework'); //default append
$this->headTitle('Zend Framework', 'set');
$this->headTitle('Zend Framework', 'prepend');
设置页面meta标签信息
$this->headMeta()->appendName('{name}', '{content}');
加载主题翻译文件
- 创建{theme name}/locale/{language}/{file name}.csv
- 模板中需要翻译的变量都使用
<?php _e({value}); ?> - 加载翻译文件的代码,一般放在模板的顶部
I18nTheme(string $domain, string $theme = null, string $locale = null)
$this->i18nTheme('main');
$this->i18nTheme('main', 'default');
$this->i18nTheme('main', null, 'en');
-
usr/locale下面创建zh-CN,就能在SEETING->system->Configurations看到语言选择,选择zh-CN。 - 创建
zh-CN/main.csv
Edit,编辑
清楚系统缓存后,进入后台首页,就能看见edit被翻译成'编辑'了。
- 模块翻译,结构如下
{module name}/locale/zh-CN/main.csv
navigation加载指定的导航
参数:name,options。name可以是'front',或者是表core_navigation_node里面的名字。options设置导航缓存。
$this->navigation('front')->render();
$this->navigation('{module name}-front')->render();
$this->navigation('front')->render(array('cache_ttl' => 86400, 'cache_level' => none, 'cache_id' =>'nav_system'));
注意:core_navigation_node里面的数据的增加是在模块的config/navigation.php文件里。
$navigation = $this->nav('front');
$navigation = $this->nav('front', array('cache_ttl' => null, 'cache_level' => 'role'))
这个类来加载全局导航,它会从core_config表读取数据,通过调用navigation来输出导航。用户可以通过后台定制自己想要的导航,operation->system->navigations,然后设置全局默认的导航。
echo $this->paginationControl($paginator, 'Sliding', 'paginator');
echo $this->paginationControl($paginator, 'Sliding', 'paginator', array('class'=> '{classname}'));
第四个参数是个分页模板赋值一个类,可以去掉。具体程序是如何分页,请看pagination。
找一个模板的位置,然后include在页面里面。
echo $this->template('{module name}:admin/{template name}');
$block = $this->template('block');
调用system模块里面的组件
include $this->templateComponent('form');
生成url
Object url(string $name = null, array $params = array(), array $options = array(), boolean $reuseMatchedParams = false)
name
路由名字,default for front-end, admin for admin-end, home for homepage and feed for feed section
$this->url('default', array('module' => 'demo', 'controller' => 'test'));
$this->url('', array('module' => 'demo', 'controller' => 'index', 'action' => 'index'));
$this->url('admin', array('controller' => 'index', 'action' => 'index'));
输出已有的区块,区块表在core_block中
$this->widget('{block name}')
