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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM