Yii框架:在控制器定义的布局中加载css和js?

My target is include difference css (or js )for difference page. And the code for link css is locate at the layout file.

My first idea is pass variable to layout, like the way you pass variable to view, but I found that it is "can not do that by design" from Yii framework forum.

So How will you to do for putting <link rel="stylesheet" ... > in the header (which inside layout file) ?

Please correct me if my concept is wrong.

You will want to go to your actions, and register the CSS file for them. Example:

function actionIndex() {
    $cs = Yii::app()->getClientScript();
    $cs->registerCssFile(Yii::app()->getBaseUrl() . '/css/myStyle.css');
    $cs->registerScriptFile(Yii::app()->getBaseUrl() . '/js/myScript.js');

    // more stuff
}

You can also pass the script loader (not CSS) an extra parameter to decide where it goes, like so:

// load on document ready
$cs->registerScriptFile(Yii::app()->getBaseUrl() . '/js/myScript.js', CClient::POS_READY); 

See the documentation for further help.