Yii Framework Forum: Yii - Access Actioncontroller In Modules - Yii Framework Forum

Jump to content

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

Yii - Access Actioncontroller In Modules Rate Topic: -----

#1 User is offline   Bang Jek 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 19-March 13
  • Location:Indonesia

Posted 29 March 2013 - 09:31 PM

Hi all,

How to call a action controller in module?

I access the url with the address

Quote

"example.com/admin/test"



I've action controller test like this

Quote

protected-modules-admin-controllers-AdminController-actionTest


but the output is

Error 404 Unable to resolve the request "admin/test".

if i call controller actionTest

Quote

protected-controllers-UserController-actionTest


and i access the url

Quote

"example.com/user/test"



it can, there is no problem

thanks for the help
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 29 March 2013 - 11:37 PM

Dear Friend

When calling a controller upon handling a request, YII does the following.

Quote

Creates a controller instance based on a route. The route should contain the controller ID and the action ID. It may also contain additional GET variables. All these must be concatenated together with slashes.

1. If the first segment is found in controllerMap, the corresponding controller configuration will be used to create the controller;
2. If the first segment is found to be a module ID, the corresponding module will be used to create the controller;
3.Otherwise, it will search under the controllerPath to create the corresponding controller. For example, if the route is "admin/user/create", then the controller will be created using the class file "protected/controllers/admin/UserController.php".


I presume that you have not declared the controllerMap proprty in main configuration file.

In our case, when we are calling,
"example.com/admin/test"


as we have admin as a module, it is going to look for TestController inside the controllers folder of the
admin module for action index.That is why it throws the error.

Then it is appropriate to call
"example.com/admin/admin/test"


If you still want admin/test to point to admin/admin/test,
we can add a rule like this.
'urlManager'=>array(
			'urlFormat'=>'path',
			'showScriptName'=>true,
			'rules'=>array(
				
				'admin/<action:\w+>'=>'admin/admin/<action>',

................................................................


Regards.
0

#3 User is offline   Bang Jek 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 19-March 13
  • Location:Indonesia

Posted 30 March 2013 - 11:17 AM

Solved...
Thanks seenivasan, :)

it was very helpful for me
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