Jump to content
Larry Ullman's Book Forums

Recommended Posts

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.

Link to post
Share on other sites
  • 3 weeks later...

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

Link to post
Share on other sites

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.

Link to post
Share on other sites
  • 3 weeks later...

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>',

),

),

Link to post
Share on other sites
  • 3 weeks later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...