N
N
nepster-web2014-03-11 22:17:59
Yii
nepster-web, 2014-03-11 22:17:59

Yii2 advanced, what is the best way to solve the issue with index files?

Installed Yii2 advanced. The index.php files remained in backend/web and frontend/web.
Implemented access to them like this, .htaccess

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
</IfModule>
 
<IfModule mod_rewrite.c>
    # deal with admin first
    RewriteCond %{REQUEST_URI} ^/(admin|assets|css|js|images)
    RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
    RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
    RewriteRule ^admin/js/(.*)$ backend/web/js/$1 [L]
    RewriteRule ^admin/images/(.*)$ backend/web/images/$1 [L]

    RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
    RewriteCond %{REQUEST_URI} ^/(admin)
    RewriteRule ^.*$ backend/web/index.php [L]

    RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
    RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
    RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
    RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
    RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
    RewriteRule ^(.*)$ frontend/web/$1 [L]

    RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
    RewriteCond %{REQUEST_URI} !index.php
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ frontend/web/index.php
</IfModule>

frontend: site.ru
backend: site.ru/admin
Everything works. However, I came across the following jamb:

In the admin panel, I want to create the following url: /admin/users/all/page/2

echo Url::toRoute(['/users/all', 'page' => 2], true); 
echo Url::toRoute(['/users/all', 'page' => 2]);

the output looks like this:
http://site.ru/admin/users/all?page=2
/admin/users/all?page=2

On the backend, my config is:
...
    'components' => [
        'request' => [
            'enableCsrfValidation' => true,
            'enableCookieValidation' => true,
            'baseUrl' => '/admin'
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,

            'rules' => [
                // Модуль 
                'users/all/page/<page>' => 'users/default/all',
                'users/all' => 'users/default/all',
                
                 //'<_a:(login|logout|error|captcha)>' => 'admin/default/<_a>',
            ]
        ],
         ....

In general, with such a configuration, it is impossible to
echo Url::toRoute(['/users/all', 'page' => 2]);
do /admin/users/all/page/2
using /admin/users/all/page/2. Tell me, please, how did someone solve such a problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2014-03-12
@merdoc

I'm making a backend to a separate secret domain.

V
vyachin, 2015-04-07
@vyachin

That should help
there are good examples here www.yiiframework.com/doc-2.0/guide-runtime-routing...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question