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 ?
You can edit /path/to/application/protected/config/main. php to change the default value. Add a request component, and configure baseUrl porperty.
Anytime you see get as the function base name, it is a getter function. Meaning you can just do: Yii::$app->urlManager->baseUrl .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With