[SOLVED] passing data from one controller to another

First of all, I’m loving Yii, many thanks to all the creators and contributors :)

I’m pretty new to MVC, so I am struggling with parts, but I have a reasonable PHP and OOP background.

Overall, I am getting my head around how it works, but I have a lot to learn…

I am building a blog site starting from the blogdemo base.

I added a Media class to handle images and video I plan to upload.

I’m using the excellent FancyUpload and CThumbCreator, both of which are working well.

I added a button to post/update called ‘Manage Media’ the links to media/admin taking the post_id with it to only show media for that post. The FancyUpload widget sits at the bottom of media/admin.

CThumbCreator is called at the end of actionUploadedFiles in FancyController.

The saves the files no problem, next I want to add the data to the database.

So just after CThumbCreator does its stuff I created a new Media object, fill its attributes and save it.

This works fine, but there is one attribute I’m struggling to get in FancyController, post_id.

edit - post_id is the foreign key in the Media model linking it to the Post model.

I have tried various ways of saving it in actionUpdate of PostController to later pick it up in FancyController, including sessions and cookies, none of which I could get working.

I’m still learning how to effectively read the class reference so I’m probably making a simple mistake, but I don’t have any errors to go on, nothing in the log file.

So my question is, what is the best way to do this? And do you have some example code? :)

Does my setup seem reasonable to you or is it fundamentally flawed in some way?

So you have created a button that links to your media controller passing GET param post_id to it. You then show FancyUpload widget in media controller telling it to upload images to fancy controller?

Sounds like you need to pass GET param post_id to fancy controller so that it can be used when saving your media model.

FancyUpload option in media controller:




'script'=>$this->createUrl('fancy/uploadedFiles',array('post_id'=>$_GET['post_id']))



In fancy controller:




$model->post_id=$_GET['post_id']

$model->save();



Oh man, I got so close to that, just wasn’t passing the param in the right place.

Thank you so much, really happy that it now works, I spent far too long on it.

One step closer to finishing my project, happydaves!