Majestic
(M Haizmann)
May 5, 2011, 5:30pm
1
Hey guys,
Im stuck again :-/.
While submitting a form, I need some extra data in the controller afterwards, which I have in the view.
So what I’m trying to do is something like that:
echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('entry' => $entry))
… but this doesn’t really work … so it’s just an example what I’m thinking of…
So, as you can see, I would need the entry object later on as well beneath the submitted form. Is there a way to do that? If yes, how can I access that object in the controller?
Thanks in advance,
Mayjestic
zaccaria
(Matteo Falsitta)
May 6, 2011, 11:35am
3
You cannot pass php objects trought html.
You should pass some parameter and in the controller retrive from the database the object you need.
Majestic
(M Haizmann)
May 6, 2011, 1:31pm
4
ahh ok, so how can I pass a parameter? … in this case the ID? Could you give me an example code snippet please?
Tanks so far!
Asgaroth
(Asgaroth Belem)
May 6, 2011, 4:09pm
5
You can change your form action so send the ID of the object your need.
for example you can make your action
$this->createUrl('', array('entry_id' => $entry->id));
which will generate something like ‘?r=currentController/currentAction&entry_id=1’
That way after submitting the form you can retrieve your object from the database
Entry::model()->findByPk($_GET["entry_id"]);
Majestic
(M Haizmann)
May 21, 2011, 9:26am
6
Thanks a lot for your help,
i finally solved it with a hidden field like that:
<?php echo CHtml::activeHiddenField($entry, 'entry_id');?>
which I received in the controller like that:
$entry = Entry::model()->findByPk($_POST['Entry']['entry_id']);