0

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.

This my application dir

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/. So the view displayed, but it's view mashed-up and all button didn't do any action when clicked.

Anyone know why the module didn't access the manual_general.css and upload_header.js from backend/web/? and how I can solve this problem?

Any help, will be appreciated. Thanks :)

EDITED:

This is the code in mi view.php to connect to .js and .css

<link rel="stylesheet" type="text/css" href="../../../../web/css/manual_general.css">
<script type="text/javascript" src="../../../../web/js/upload_header.js"></script>
5
  • Try using yii\helpers\Url::to. Example: <link rel="stylesheet" type="text/css" href="<?= Url::to('@web/css/manual_general.css') ?>"> Commented Feb 2, 2017 at 22:01
  • @sonofagun I've tried your suggestion, but it didn't solve the problem. Commented Feb 3, 2017 at 3:27
  • SOLVED! Big thanks to @sonofagun :D Commented Feb 3, 2017 at 4:07
  • Glad to hear it! I'll enter it as an answer - please mark it correct. Commented Feb 3, 2017 at 17:02
  • @sonofagun Done! :) Commented Feb 4, 2017 at 11:04

1 Answer 1

1

Try using yii\helpers\Url::to, like:

<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):

<?php $this->registerCssFile('@web/css/manual_general.css'); ?>
<?php $this->registerJsFile('@web/js/upload_header.js'); ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.