E
E
EVOSandru62014-12-12 11:52:33
Yii
EVOSandru6, 2014-12-12 11:52:33

How to create and apply a separate config for a module in Yii?

Good afternoon, is it possible to create a separate config and entry point in the admin module or somehow separate it at the application level. I need to change the rules for the UrlManager while being in the module.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
developinwed, 2015-01-19
@EVOSandru6

In .htaccess

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^.*$ admin.php [L]

# если директория или файл существуют, использовать их напрямую
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# иначе отправлять запрос на файл index.php
RewriteRule . index.php

Here the line RewriteCond %{REQUEST_URI} ^/(admin) means that if the url starts with admin, then we refer to admin.php - this will be your entry point. In admin.php - specify the desired config, for example like this:
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/admin.php';

//defined('YII_DEBUG') or define('YII_DEBUG',true);
//defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

require_once($yii);
Yii::createWebApplication($config)->run();

Then in protected/config/admin.php you can specify custom rules for the admin module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question