YII2笔记之三

activeform布局
findAll等不能满足where, order by, limit,底层调用了findByCondition
col-md col-lg的使用

 


view的方法,前三个常用
render 把变量传递给页面,页面结果作为content变量传递给布局文件
renderPartial 只生成view文件,不使用布局文件
renderAjax 
renderContent 将变量传递到布局文件
renderFile 编译php或其他文件
renderPartial和renderContent相结合等于render
文件路径指定方式:别名@app完整路径,//当前app起路径,/当前module的views起路径,viewcontextinterface返回的view(只有view名字如about,此种居多),getViewFile上次render使用的view文件目录(两次连续使用render,render的页面中再使用render)

controller的render实际调用了view的render函数,view的render不用调用布局文件

 

view中注册css等:css等在文件开头,js有POS_HEAD(head结束标签前),POS_BEGIN(body开始标签后),POS_END(body结束标签前),POS_LOAD(JQuery标签中),

POS_READY几种;文件先后顺序
$this->registerMetaTag()
$this->registerLinkTag($options)
$this->registerCss($css)代码
$this->registerCssFile($url)文件
$this->registerJs($js)
$this->registerJsFile($url)
asset bundle

 

 

生成顺序:meta link css js
css、js文件 的depends

 


controller定义了布局变量$layout
module里面定义了布局变量$layout
先查看当前controller里面有没有定义布局变量,没有则查找所在module里面定义的布局变量,还没有则查找父级module定义的布局变量
指定布局文件:false(不使用),null(用module中的),字符串(指定文件,别名方式、/开头、当前module中定义的)
布局文件的结果可以继续传递给另一个布局文件(beginContent)

 


向布局文件传递多个变量(yii本身只能传递一个)
view中,lulucms/widgets/InhritLayout
$this->beginBlock('content1')
....
$this->endBlock()
$this->beginBlock('content2')
....
$this->endBlock()
布局文件就可以使用变量$content1、$content2显示他们中间的内容

 

 

controller传递变量方式:

1 render时一并传入:render("about",['var'=>'value'])
2 赋值给view对象
$view=\Yii::$app->getView()
$view->params['var']='value'
3 view对象中
$context = $this->context;
context即为controller,布局文件中也可以
widget中context为view

posted on 2015-10-23 11:44  小交响曲  阅读(2188)  评论(0编辑  收藏  举报

导航