marchemike
marchemike

Reputation: 3277

Selecting a specific controller in Yii

I'm fairly new to yii and I've taken over somebody else work. I'm trying to send an action to my controller using my view, however, my form is using a different controller. The view itself uses the default controller, my form is using another controller on the same folder.

Whenever I try the changing the action path, the path does not use the default URI path navigation(I don't know how the over guy did it).

When I checked my Yii::app()->controller in the view that I'm using the _controllerPath says it gets pointed to this filepath

\application\backend\modules\module1\controllers

and my file structure is:

module1\controllers\controller1.php(my default controller for this view) module1\controllers\controller2.php(the controller I'm trying to connect)

now I'm trying to send my form to the same filepath, but whenever I try to submit it, it says that the controller could not be found.

My action code is:

'action' => 'controller2/create', (the function name is actionCreate)

and it always tells me error 404(which means I am not connecting to the right path), so how do I know if I'm connecting to the right path? I have been stuck in this for 2 days, changing the file path.

Upvotes: 1

Views: 246

Answers (1)

pratik-acharya
pratik-acharya

Reputation: 418

you can use this as action in the form :

 <?php echo CController::createUrl('anothercontroller/action');?>

 <?php echo CController::createUrl('controller2/create');?>

or,

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'form-id',
    'action' => CController::createUrl('anothercontroller/action'), 

)); ?>

Upvotes: 2

Related Questions