Separate URL for front-end and for back-end

2.2k views Asked by At

I am new to Yii framework.

I have downloaded Yii2, and Yii2 Advanced Application.
I want to create 2 URLs for front and for admin panel.

Front-end URL: http://localhost/advanced
Back-end URL: http://localhost/advanced/admin

How can I do this?

3

There are 3 answers

8
Mat On

The url routing subject is quite broad. You should start by reading the detailled documentation http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html

Basically, you register an urlManager component in the application config. In the following example, front and admin are 2 controllers with an index action.

new yii\web\Application([
    ...
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false
            'rules' => [
                'advanced' => 'front/index'
                'advanced/admin' => 'admin/index'
            ]
        ],
    ]
    ...
])
0
rahul sharma On
  1. After downloading the Yii2 advanced template archive. Install the advanced Yii2 using this link Yii2 advanced installation guide
  2. Follow all the steps in "Preparing application" section of above url.
  3. After following all steps you are ready to go. Now you can access frontend and backend i.e For ex: FRONTEND: http://localhost/advanced/forntend/web BACKEND: http://localhost/advanced/backend/web
  4. Create admin panel in yii2 backend. Please follow this url Backend Admin panel

I know i am late to answer but i want to help other guys which are new to Yii2. I hope my points will be helpful.

0
jacmoe On

The advanced application template was never designed to do that because it is two separate applications that requires two separate domains (subdomain for 'admin' is fine).

What you want to use instead is yii2-app-practical-a which does exactly what you want. :)

You have the main application you can access by your main URL - http://localhost/advanced and a back-end you can access by the main URL with admin appended: http://localhost/advanced/admin.