Home >PHP Framework >YII >How to use jquery in yii

How to use jquery in yii

(*-*)浩
(*-*)浩Original
2019-11-05 11:34:182363browse

When I first come into contact with Yii, I may be a little confused about the resource management of assets inside. For example, when using jquery, some of the widgets that come with Yii's system will automatically load jquery. But what if you don't have these widgets and want to load jquery?

How to use jquery in yii

The solution provided by yii is: Yii::app()->clientScript->registerCoreScript('jquery'); . Through this registration statement, jquery is prevented from being called twice. If the system (recommended learning: yii tutorial)

is automatically loaded, it will not be registered. If not, Then load jquery through this statement.

Code:

<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.js" 
type="text/javascript"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/nav.js" 
type="text/javascript"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/menu.js" 
type="text/javascript"></script>

php Code:

<?phpYii::app()->clientScript->registerCoreScript(&#39;jquery&#39;);

Yii::app()->clientScript->registerScriptFile(Yii::app()->request-

>baseUrl.&#39;/js/nav.js&#39;);

Yii::app()->clientScript->registerScriptFile(Yii::app()->request-

>baseUrl.&#39;/js/menu.js&#39;);?>

The above is the detailed content of How to use jquery in yii. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to set layouts in yiiNext article:How to set layouts in yii