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

How to use jquery in yii

(*-*)浩
Release: 2019-11-05 11:34:18
Original
2335 people have browsed it

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>
Copy after login

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;);?>
Copy after login

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!

Related labels:
yii
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template