Ok Yii is Very powerful! and flexible.
This is how I have set-up my parent controller to handle css and meta tags.
class BackendController extends CController
{
public $cssFiles = array('reset','text2','960','site2');
public function init(){
// get the default css and meta tags
$metaTags = array( 'description'=>'this is the page description',
'keywords'=>'keyword one, keyword two,keyword three',
'language'=>'en',
'generator'=>'Yii!'
);
$this->initCss();
$this->initMetaTags($metaTags);
}
public function initCss($cssFiles = null){
// this registers a bunch of css files, the render command adds them to the web doc
if(!$cssFiles){
$cssFiles = $this->cssFiles; // if no css files specified then use the default css files
}
foreach($cssFiles as $css){
Yii::app()->clientScript->registerCssFile('/css/'.$css.'.css', '');
}
}
public function initMetaTags($metaTags = null){
// meta tags
if($metaTags){
foreach(array_keys($metaTags) as $metaTag)
{
Yii::app()->clientScript->registerMetaTag($metaTags[$metaTag],$metaTag);
}
} else {
return;
}
}
...snip
So each child controller now has default css and default meta tags, but usually you will want specific meta tags (especially description and in my case geo location tags) I can now do the following for controller specific (actual controller/action) specific meta tags.
class SiteKeysController extends BackendController
{
..snip..
/**
* Lists all models.
*/
public function actionList()
{
$criteria=new CDbCriteria;
$pages=new CPagination(SiteKeys::model()->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$models=SiteKeys::model()->findAll($criteria);
// meta tags and css
Yii::app()->clientScript->reset(); // this resets ALL registrations
$this->initCss();
$metaTags = array( 'description'=>'This is customized for the site keys list',
'keywords'=>'Yippee Kai eh!',
'language'=>'en',
'generator'=>'Yii!'
);
$this->initMetaTags($metaTags);
$this->render('list',array(
'models'=>$models,
'pages'=>$pages,
));
}
This works exactly the way I would like it, of course I plan to pull the values from a database for the individual pages (still on a vertical learning curve with yii).
Question:Yii::app()->clientScript->reset(); is this the only way to remove meta tags / css / javascript ?
Can items be removed individually?
Also the css and javascript files are rendered nicely (visually)
<meta content="This is customized for the site keys list" name="description" /><meta content="Yippee Ki eh!" name="keywords" /><meta content="en" name="language" /><meta content="Yii!" name="generator" /><link rel="stylesheet" type="text/css" href="/css/reset.css" />
<link rel="stylesheet" type="text/css" href="/css/text2.css" />
<link rel="stylesheet" type="text/css" href="/css/960.css" />
<link rel="stylesheet" type="text/css" href="/css/site2.css" />
<link rel="stylesheet" type="text/css" href="/assets/f913186d/treeview/jquery.treeview.css" />
<script type="text/javascript" src="/assets/f913186d/jquery.js"></script>
<script type="text/javascript" src="/assets/f913186d/jquery.cookie.js"></script>
<script type="text/javascript" src="/assets/f913186d/jquery.treeview.js"></script>
<script type="text/javascript" src="/assets/f913186d/jquery.treeview.async.js"></script>
it would be more desirable to have a cleaner output (not a big problem of course)
<meta content="This is customized for the site keys list" name="description" />
<meta content="Yippee Ki eh!" name="keywords" />
<meta content="en" name="language" />
<meta content="Yii!" name="generator" />
also content before name is unusual in meta tag definitions, I guess I would have to either (I won’t ever do this) hack the core or extend it. Is that true?
Thanks,
doodle