[英]PHP: How do I can access .js and .csss in Web dir from my Module in yii2?
I've an application build in Yii2 framework, and I've develop the application in backend side , but know I want to copy them become a module. 我已经在Yii2框架中构建了一个应用程序,并且已经在后端开发了该应用程序,但是知道我想将它们复制为一个模块。
backend
--modules
--pstk
--controllers
--ValidationController.php
--DefaultController.php
--InterviewController.php
--StudentController.php
--SiteController.php
--UsersController.php
--models
--Validation.php
--Interview.php
--Student.php
--Users.php
--views
--validation
--_form.php
--view.php
--index.php
--update.php
--create.php
--interview
--student
--users
--Module.php
--web
--css
--manual_general.css
--js
--upload_header.js
--style
For example I've successfully run view.php
from the module in browser, but the module can't access the .css
and .js
from backend/web/
. 例如,我已经从浏览器中的模块成功运行了
view.php
,但是该模块无法从backend/web/
访问.css
和.js
。 So the view displayed, but it's view mashed-up and all button didn't do any action when clicked. 这样便显示了视图,但视图是混搭的,单击时所有按钮均未执行任何操作。
manual_general.css
and upload_header.js
from backend/web/
? backend/web/
访问manual_general.css
和upload_header.js
吗? and how I can solve this problem? Any help, will be appreciated. 任何帮助将不胜感激。 Thanks :)
谢谢 :)
This is the code in mi view.php to connect to .js
and .css
这是mi view.php中连接到
.js
和.css
<link rel="stylesheet" type="text/css" href="../../../../web/css/manual_general.css">
<script type="text/javascript" src="../../../../web/js/upload_header.js"></script>
Try using yii\\helpers\\Url::to, like: 尝试使用yii \\ helpers \\ Url :: to,例如:
<link rel="stylesheet" type="text/css" href="<?= Url::to('@web/css/manual_general.css') ?>">
<script type="text/javascript" src="<?= Url::to('@web/js/upload_header.js') ?>"></script>
Alternatively, in view.php you may do (assuming $this is your View instance): 或者,您可以在view.php中做(假设$ this是您的View实例):
<?php $this->registerCssFile('@web/css/manual_general.css'); ?>
<?php $this->registerJsFile('@web/js/upload_header.js'); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.