H
H
HaruAtari2014-01-21 12:18:01
Yii
HaruAtari, 2014-01-21 12:18:01

Is it possible in Yii to place assets files in module directories?

Good afternoon.
There is a site on Yii. Broken down into modules. The directory structure is standard:

css/
-users/
--style1.css
--style2.css
-bids/
--style1.css
--style2.css
protected/
-modules/
--users/
--- ...
--bids/
--- ...

I would like to make sure that style sheets and js files are not in a shared folder, but each in the directory of its module. To make the module standalone.
But access to protected for apache is closed. Can you please tell me how to implement such a scheme? Is it possible to open files from a protected directory with issets?
Who faced a similar task, tell me how to implement such an approach?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
nikel303, 2014-01-22
@HaruAtari

For example:

class AdminModule extends CWebModule {

    public $baseAssetsUrl = null;

    public function init() {

        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
        ));

        if ($this->baseAssetsUrl === null) {
            $this->baseAssetsUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('admin.assets'), false, -1, (bool) YII_DEBUG);
        }
    }

}

And in views you take the path like this:
Yii::app()->getClientScript()->registerCssFile($this->module->baseAssetsUrl . '/css/style.css');

R
Roman Makarov, 2014-01-21
@vollossy

CAssetManager ?

V
Vit, 2014-01-21
@fornit1917

To make the module standalone.

You have the wrong question. In order for a module to be standalone, it does not need an assets folder. It is only necessary that it contains all the necessary resources, and where they will be published is completely unimportant for autonomy.
In addition, modules in yii cannot be completely, completely autonomous, in principle they cannot be used separately from the parent application, see the documentation www.yiiframework.com/doc/guide/1.1/en/basics.module :
Making the module directory accessible from the web is not very good. Perhaps you need to look not in the direction of the modules, but in the direction of splitting the yii application into several other applications, for example habrahabr.ru/post/180679 or habrahabr.ru/post/207454

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question