calling an action of another controller

I have property controller which has create action,

also i have propertyImage controller which has create action!

now how do I call create action of propertyImage controller in property controller create action?

I have code similar to this…

this code is in property/CreateAction.php




Yii::import('application.controllers.PropertyImageController');

Yii::import('application.controllers.propertyImage.CreateAction');

$propertyImageController=new PropertyImageController('propertyImage');

$createImage=new CreateAction($propertyImageController,'create');

$createImage->run();

But this says "problem loading page"…

Regards…

An action is not supposed to be an API which can be called from another action.

So if your property/create needs to do some more work after calling propertyimage/create, then you should consider some other approach.

If you just want the property/create and the propertyimage/create actions to perform exactly the some code, you may use the forward() function.

Thanks a lot Onman …

forward() might be helpful. I didn’t notice it at first!

But, my point is, when i’m creating a property, i want to create a new image related to it! Now, I don’t want to totally give control to that controller! as render should be called from property controller and not from image controller.

Ok, situation is , when i’m creating a property, i’m checking if user email is existing, if not i’m adding to user table(i.e. new user created). Now, if i add user creation into property table, then its logically wrong isn’t it? user creation should be handled by user controller itself. as there might be other events where i would like to handle user creation or updates etc. So to avoid duplicate code, i wanted to keep it in separate classes…

What is behavior? or event? Can that be used in any way, in such situations?

You may want to create 1 (UserModel) or 2 (UserModel and PropertyImageModel) models.

On the model you can then create your api’s (methods) which handle the task, e.g.

UserModel->createUser($email);

PropertyModel->createImage($imgName);