控制器
public function actionSend(){
Yii::app()->clientScript->registerCoreScript('myplugin');
$this->render();
echo 'submit';
}
Run Code Online (Sandbox Code Playgroud)
主文件
'clientScript' =>array(
'packages'=>array(
'myplugin'=>array(
'baseUrl'=>'myload/',
'js'=>array('myload/bow.js'),
),
'boot'=>array( //set others js libraries
'baseUrl'=>'myload/',
'js'=>array('myload/bow2.js'),
'css'=>array( // and css
// 'css/bootstrap.min.css',
// 'css/custom.css',
// 'css/bootstrap-responsive.min.css',
),
'depends'=>array('myplugin'), // cause load myplugin before load this.
)
) )
Run Code Online (Sandbox Code Playgroud)
错误:
属性“CWebApplication.clientScript”是只读的。
你必须把clientScript里面components像:
'components'=>array(
'clientScript' => array(
//something depend on your configure
),
),
Run Code Online (Sandbox Code Playgroud)
此外,此链接对您很有用:http : //www.yiiframework.com/forum/index.php?/ topic/1421-where-to-put-javascript-file /