distortionzzz 3 Posted November 21, 2012 Report Share Posted November 21, 2012 Hi everyone, I'm going slightly beyond the scope of part 1 of this book. I want to create my own routes, an example being. Instead of /user/register, I want to use just /register. I thought i could just modify the URL Manager config and add something like this: '<action:\w+>'=>'<controller>/<action>', This wouldn't have been an ideal solution anyway incase of duplicate action names. Does anyone have a solution to this. Some kind of override. Thank you. Quote Link to post Share on other sites
distortionzzz 3 Posted November 21, 2012 Author Report Share Posted November 21, 2012 Hi again, I can't believe I solved this only minutes after asking for help I simply added the below to the UrlManager 'register'=>'/user/register' And I thought I had to do something fancy Thanks Anyway 1 Quote Link to post Share on other sites
Larry 428 Posted November 21, 2012 Report Share Posted November 21, 2012 Yep, that will work. Kudos for figuring it out and thanks for sharing your solution. Quote Link to post Share on other sites
Solid 0 Posted December 10, 2012 Report Share Posted December 10, 2012 Thx, nice fix. I was struggeling a bit at first, but then i figured out what i did wrong. You have to remember the / in front of register when you add it to the menu, or it will go to /site/register and fail. You can also add: '/'=>'/site/index' and set the home-link to just /. Thank you Simon Quote Link to post Share on other sites
Larry 428 Posted December 18, 2012 Report Share Posted December 18, 2012 I should have mentioned it before, but it should be just: 'register'=>'user/register' You shouldn't need the initial slash. Also, there's really no need to set / to site/index, as site/index is the default controller/action. That's an unnecessary rule, and unnecessary rules confuse things and hurt performance. Quote Link to post Share on other sites
Edward 108 Posted December 18, 2012 Report Share Posted December 18, 2012 But a website would look url ugly with site controller after the domain name. So how do we go about this? Quote Link to post Share on other sites
Antonio Conte 426 Posted December 18, 2012 Report Share Posted December 18, 2012 It's the main rule. No need to declare it. This is why it works to go to domain.com/index.php or domain.com and still see the default screen. Quote Link to post Share on other sites
nathor240 0 Posted January 3, 2013 Report Share Posted January 3, 2013 Spending hours on trying to gett rid of the index.php in the url. Working on windows maching with XAMPP 1.8.0. and having no luck. Any help would greatly be appreciated. I the url looks good now but I just get a 404 error. I comment out the 'showScriptName'=>false, line in the urlManager config array and the 404 error goes away but the url is messing again. I Checked the httpd.conf file to make sure overrides would be taken from the .htaccess file in the web root. # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All I wrote and saved the htaccess file in the web root where the index.php is, you can see I've tried a few different things. #Options +FollowSymLinks RewriteEngine on #RewriteBase / # if a directory or a file exists, use it directly RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index.php) # otherwise forward it to index.php #RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA] RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA] I went in and modified the urlManager array in the main.php config file 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( 'contact' => array('site/contact', 'caseSensitive'=>false), 'login' => array('site/login', 'caseSensitive'=>false), '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ), Quote Link to post Share on other sites
Larry 428 Posted January 22, 2013 Report Share Posted January 22, 2013 Sorry. This slipped through the cracks for me. Are you still having a problem with this? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.