Start by forcing the $id parameter to the edit action, then pass on the
selected ID to the view. Then on the view set the action of the form to
include this id.
So on the controller set the data regardless if you got submitted
information or not, like so:
function edit ($id)
{
$this->User->id = $id;
$record = $this->User->read();
if (!empty($this->data))
{
if ($this->User->save($this->data['User'], true,
array('email',
'date_expires'))) {
$this->redirect('/users/index');
}
}
else
{
$this->data = $record;
}
$this->set('record', $record);
}
Finally on the view when you need to print stuff from readonly values, use
$record, like so:
<h2>User <?php echo $record['User']['username']; ?></h2>
And don't forget to set the form action properly:
<?php echo $form->create('User', array('action'=>'/users/edit/' .
$record['User']['id'])); ?>
This last form code is for 1.2, for 1.1 do:
<?php echo $html->formTag('/users/edit/' . $record['User']['id']); ?>
-MI
---------------------------------------------------------------------------
Remember, smart coders answer ten questions for every question they ask.
So be smart, be cool, and share your knowledge.
BAKE ON!
blog: http://www.MarianoIglesias.com.ar
-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de [EMAIL PROTECTED]
Enviado el: Jueves, 22 de Febrero de 2007 10:55 a.m.
Para: Cake PHP
Asunto: Problem with Controller: How to mix db and posted values on edit?
I want the users of my application to be able to change only certain
aspects of their profile. Limiting the fields in the save method
prevents users from modifying fields like registration date or
username. My problem is: If there are validation errors these "read-
only" properties of the model disappear.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---