Yii Framework Forum: Change default controller / action - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Change default controller / action Rate Topic: -----

#1 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 02 November 2009 - 01:46 AM

How to change the default controller / action in the UrlManager ?
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 02 November 2009 - 02:13 AM

*
POPULAR

You can't change that in the urlManager, but what you can do of course is:

...

'components' => array(
  'urlManager' => array(
    'rules' => array(
      '' => 'controller/action',
    ),
  ),
),

...


So when you request the index page, the controller "controller" with action "action" will be triggered.

To really modify the core defaults (site/index), you have to modify CWebApplication::defaultController and CController::defaultAction.

In config:

return array(
   
   'defaultController' => 'test',
   
   ...


and in your controller:


class TestController extends CController
{

  public $defaultAction = 'test';

  public function actionTest()
  {

  }

}



I guess the first solution is what you're looking for?!
6

#3 User is offline   datashaman 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 27-September 09
  • Location:Cape Town, South Africa

Posted 02 November 2009 - 03:44 AM

For a more dynamic approach to changing the defaultController (amongst other things), look here.
0

#4 User is offline   annii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 22-May 12

Posted 02 June 2012 - 11:44 PM

View PostY!!, on 02 November 2009 - 02:13 AM, said:

You can't change that in the urlManager, but what you can do of course is:

...

'components' => array(
  'urlManager' => array(
    'rules' => array(
      '' => 'controller/action',
    ),
  ),
),

...


I am a yii newbie...but i wanted to say that the above code worked for me after i added another key value pair to the urlManager array

...

'components' => array(
  'urlManager' => array(
    'urlFormat'=>'path',    //<---------This line
    'rules' => array(
      '' => 'controller/action',
    ),
  ),
),

...

0

#5 User is offline   dave101ua 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 23-April 12

Posted 12 June 2012 - 06:28 AM

Hello!
I have similiar question

if I type in url name of controller which not exists (let's say "sdf") then I get error:

Quote

Error 404
Unable to resolve the request "sdf".



can we do that if unexisted controller is requested then defaultcontroller is used ?
Yii newbie
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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