Answer the question
In order to leave comments, you need to log in
How can I disable ClientScript script packages in Yii?
In main.php config:
'clientScript'=>array(
'coreScriptPosition'=>CClientScript::POS_END,
'packages'=>array(
'jquery'=>array(
'baseUrl'=>'/themes/classic/js/',
'js'=>array('jquery.min.js'),
),
'bootstrap'=>array(
'baseUrl' => '/themes/classic/plugins/bootstrap/',
'js'=>array('js/bootstrap.min.js'),
'css' => array('css/reset.css','css/bootstrap.css'),
'depends'=>array('jquery'),
),
'theme'=>array(
'baseUrl' => '/themes/classic/',
'js'=>array('js/site.js'),
'css' => array('css/style.css'),
'depends'=>array('jquery','bootstrap'),
),
public function beforeAction($action) {
if(parent::beforeAction($action) ) {
Yii::app()->clientScript->registerPackage('theme');
return true;
}
return false;
}
public function actionQuickview() {
$this->layout = 'blank';
$id = Yii::app()->request->getParam('id',0);
//$this->disableScript(array('quickview')); // В идеале как-то тут отключить подключение THEME package
$product = Goods::model()->findByPk($id);
if($product) {
$this->render('_goods_quickview',array('product'=>$product));
} else {
throw new CHttpException(404,'Страница ошибки 404');
}
Yii::app()->end();
}
Answer the question
In order to leave comments, you need to log in
Since you did it, you can't do it. All packages must be connected explicitly!!!! in the header of the template and only those that are necessary for this template. If you have a package (s) that are used in several templates - make your own layout for them, inherit from the main one and include common packages already in it.
If you return the result of an ajax request - use renderPartial, the last parameter will help you disable the transfer of css + js
In layout, I did not connect any additional js / css scripts / styles at all - I included all scripts in the previous version of the application (before using beforeAction) in the corresponding view. In the layout, I connect only statics, something that will never change in the course of work. For example, the site menu, search bar, site footer and the like, I hope I'm doing it right?
In theory, I wanted to use the following structure: the "theme" script package is used on the entire site except for ajax uploads, the "cart" package is also needed on the entire site, working with the cart. Connect the rest as needed. But of course there are visibility problems, for example, "cart" is needed on the list of products, and at the same time inside the content of the modal window loaded via ajax, moreover, on the same page. Consider, on the element of the list of goods there is a button "add to cart" and in the modal window there is the same button in terms of functionality. And both of them pass product data to the controller.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question