Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to setup url friendly in yii framework automatically

I just learning yii framework and read this tutorial about yii how to setup url

but I have no idea, suppose i have 10 controllers, should I define one by one controllers in the config file ? is there a better way to setup url friendly like www.yoursite.com/yourController/yourAction/yourID for all controller ?

I think codeigniter did that automatically ... how about yii ?

like image 747
nightingale2k1 Avatar asked Jul 27 '09 18:07

nightingale2k1


People also ask

How can I change base URL in Yii?

You can edit /path/to/application/protected/config/main. php to change the default value. Add a request component, and configure baseUrl porperty.

How can I get base URL in Yii?

Anytime you see get as the function base name, it is a getter function. Meaning you can just do: Yii::$app->urlManager->baseUrl .

What is routing in Yii Framework?

When a Yii application starts processing a requested URL, the first step it takes is to parse the URL into a route. The route is then used to instantiate the corresponding controller action to handle the request. This whole process is called routing.

Is Yii Framework easy to learn?

As @samdark said, Yii is easy to learn and use but you need some previous knowledge. My advice is going step by step through the official documentation doing some test project. In a couple of months you will be able to do useful stuff.


1 Answers

In /protected/config/main.php add..

    'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName' => false,      
        ),
    ),

In your web root an .htaccess..

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
like image 152
Chris Avatar answered Sep 20 '22 23:09

Chris