Yii Framework Forum: SOLVED: Problem with URL rewrites - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

SOLVED: Problem with URL rewrites Rate Topic: -----

#1 User is offline   enfield 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 288
  • Joined: 12-January 11

Posted 05 May 2011 - 11:50 PM

I have been through the documentation and tutuorials and many forum posts (unfortunately currently links posted in the forum are not working).

I am trying to rewrite my urls for entire directories...

I got static pages to rewrite by modifying the urlManager like this..

'login'=>'user/login',


which allows
www.site.com/user/login.php
to display as
www.site.com/login.php


The goal is to be able to take
user/
out of everything under the user directory.

In Using search engine and user friendly URLs it is mentioned to do

class ActiveRecord extends CActiveRecord
{
    public function getUrl()
    {
        $controller=get_class($this);
        $controller[0]=strtolower($controller[0]);
        $params=array('id'=>$this->id);
        // add the title parameter to the URL
        if($this->hasAttribute('title'))
            $params['title']=$this->title;
        return Yii::app()->urlManager->createUrl($controller.'/view', $params);
    }
}
 
// class Post extends ActiveRecord { ... } 


Is this the approach that I should be taking rather than modifying the urlManager in the config file?
1

#2 User is offline   enfield 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 288
  • Joined: 12-January 11

Posted 07 May 2011 - 03:31 AM

Well thanks to the help received from phpnode on irc here is a solution

'<_a:(login|index|update|etc)>' => 'user/<_a>',

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users