admin管理员组文章数量:1391993
is it possible to register Javascript in a controller action in Yii2?
More or less I think:
class MyController extends yii\web\Controller {
public function actionView(){
//Is it possible to register Javascript here?
return $this->render('view');
}
}
is it possible to register Javascript in a controller action in Yii2?
More or less I think:
class MyController extends yii\web\Controller {
public function actionView(){
//Is it possible to register Javascript here?
return $this->render('view');
}
}
Share
Improve this question
asked Dec 1, 2017 at 15:53
Alberto FavaroAlberto Favaro
1,8304 gold badges24 silver badges47 bronze badges
1
- In yii 1.x you could register the script through clientScript ponent – Alberto Favaro Commented Dec 1, 2017 at 16:39
1 Answer
Reset to default 6Your controller gives you access to its view, which in turn allows you to render JS.
$this->getView()->registerJs("yourJsGoesHere");
http://www.yiiframework./doc-2.0/yii-base-controller.html#getView()-detail
http://www.yiiframework./doc-2.0/yii-web-view.html#registerJs()-detail
本文标签: javascriptYii2 register JS in controllerStack Overflow
版权声明:本文标题:javascript - Yii2 register JS in controller - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744663763a2618405.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论