You can also try this code in your edit.cpt file
*<?php echo $this->Form->create('User', array('action' => 'edit/'.$id));?>*
where $id is set from the edit() function in controller
On Tuesday, July 17, 2012 3:12:25 PM UTC+5:30, Banana Man wrote:
>
> So when you go to the first edit screen the id is being passed in the URL
> from the link:
>
> <?php echo $this->Html->link(__('Edit'), array('action' => 'edit',
> $user['User']['id'])); ?> :
>
> but no id is specified when you click the submit link on the edit page.
> If i then add a hidden field to the edit page as discussed above it should
> pass the id?
>
> I have also amended my controller as follows:
>
>
> public function edit($id = null) {
> *$this->set('id',$id);*
> $this->User->id = $id;
> if (!$this->User->exists()) {
> throw new NotFoundException(__('Invalid user'));
> }
> if ($this->request->is('post') || $this->request->is('put')) {
> if ($this->User->save($this->request->data)) {
> $this->Session->setFlash(__('The user has been saved'));
> $this->redirect(array('action' => 'index'));
> } else {
> $this->Session->setFlash(__('The user could not be saved.
> Please, try again.'));
> }
> } else {
> $this->request->data = $this->User->read(null, $id);
> unset($this->request->data['User']['password']);
> }
> $this->set('title_for_layout', 'Edit Account');
> }
>
>
> When i try this i just get an error message on the second submit attempt
> saying:
>
>
> *Error: *The requested address *'/users/edit'* was not found on this server.
>
>
> So it seems i am passing the id incorrectly on the second edit. Have i
> placed the code incorrectly in the controller?
>
>
> Also, how come none of this is mentioned in the Tutorial document? It seems
> strange that they would be listing broken code on one of the main tutorials
> on the cake site?
>
>
> Thanks,
>
> Ronan
>
>
> On Tuesday, July 17, 2012 9:06:05 AM UTC+2, Bharat Maheshwari wrote:
>>
>>
>> you have to post a id set from the action
>>
>> in your controller :-
>>
>> $this->set('id',$id);
>>
>> in your view
>>
>> $this->Form->hidden('id',array('value'=>$id));
>> On Saturday, July 14, 2012 12:21:11 PM UTC+5:30, chuminh wrote:
>>>
>>> I am having the same problem with edit. I got exactly the same code as
>>> above. but when I try to edit and save the data, it does not save, it gives
>>> me flash message. I wonder what is wrong with the code because i follow
>>> this edit function from blog tutorial.
>>>
>>> Thanks
>>>
>>> On Wednesday, July 11, 2012 11:47:44 PM UTC+10, Max Dörfler wrote:
>>>>
>>>> I guess in your view you have to pass in the id (echo
>>>> $this->Form->input('id');). This should include a hidden id field.
>>>> I wonder why it works the first time (without leaving a field blank).
>>>> Are you sure the user gets edited and not a new user created? Because when
>>>> you save $this->request->data, the data shouldn't contain the id if you
>>>> didn't pass it from the view!
>>>>
>>>> On 07/11/2012 03:20 PM, Banana Man wrote:
>>>>
>>>> Hi,
>>>>
>>>> I am trying to setup an Edit User authentication action. I have
>>>> authentication working fine for adding a user but when i try to edit a
>>>> user
>>>> i am running into a problem.
>>>>
>>>> If i try to edit a user when all information supplied passes
>>>> validation it works fine (URL: http://localhost/users/edit/3). If
>>>> however i leave a textfield blank when i am validating it against
>>>> 'notEmpty' the first time i hit the form submit button it works as
>>>> expected
>>>> and reloads the edit user page with the validation error displayed (URL:
>>>> http://localhost/users/edit/3). If i do nothing and try to submit the
>>>> form again with the blank textfield i now get redirected to
>>>> http://localhost/users/edit with an Invalid User message "*Error: *The
>>>> requested address
>>>> *'/users/edit'* was not found on this server."
>>>>
>>>> <!-- app/Controller/UsersController.php -->
>>>> public function edit($id = null) {
>>>> $this->User->id = $id;
>>>> if (!$this->User->exists()) {
>>>> throw new NotFoundException(__('Invalid user'));
>>>> }
>>>> if ($this->request->is('post') || $this->request->is('put')) {
>>>> if ($this->User->save($this->request->data)) {
>>>> $this->Session->setFlash(__('The user has been saved'));
>>>> $this->redirect(array('action' => 'index'));
>>>> } else {
>>>> $this->Session->setFlash(__('The user could not be
>>>> saved. Please, try again.'));
>>>> }
>>>> } else {
>>>> $this->request->data = $this->User->read(null, $id);
>>>> }
>>>> }
>>>>
>>>>
>>>>
>>>> <!-- view/users/edit.ctp -->
>>>> <div class="users form">
>>>> <?php echo $this->Form->create('User', array('action' => 'edit'));?>
>>>> <fieldset>
>>>> <legend><?php echo __('Edit User'); ?></legend>
>>>> <?php
>>>> echo $this->Session->flash();
>>>> echo $this->Form->input('firstname', array('label' => 'First Name'));
>>>> echo $this->Form->input('secondname', array('label' => 'Second
>>>> Name'));
>>>> echo $this->Form->input('address_01', array('label' => 'Address Line
>>>> 1'));
>>>> echo $this->Form->input('address_02', array('label' => 'Address Line
>>>> 2'));
>>>> echo $this->Form->input('address_03', array('label' => 'Address Line
>>>> 3'));
>>>> echo $this->Form->input('address_04', array('label' => 'Address Line
>>>> 4'));
>>>> echo $this->Form->input('tel_01', array('label' => 'Telephone'));
>>>> echo $this->Form->input('email');
>>>> echo $this->Form->hidden('role', array('value' => 'customer'));
>>>> ?>
>>>> </fieldset>
>>>> <?php echo $this->Form->end(__('Submit'));?>
>>>> </div>
>>>> <div class="actions">
>>>> <h5><?php echo __('Actions'); ?></h5>
>>>> <ul>
>>>>
>>>> <li><?php echo $this->Html->link(__('List Users'), array('action' =>
>>>> 'index'));?></li>
>>>> </ul>
>>>> </div>
>>>>
>>>>
>>>>
>>>> Does anyone know why i am getting redirected on the second submit?
>>>>
>>>> Thanks!
>>>> --
>>>> Our newest site for the community: CakePHP Video Tutorials
>>>> http://tv.cakephp.org
>>>> Check out the new CakePHP Questions site http://ask.cakephp.org and
>>>> help others with their CakePHP related questions.
>>>>
>>>>
>>>> To unsubscribe from this group, send email to
>>>> [email protected] For more options, visit this
>>>> group at http://groups.google.com/group/cake-php
>>>>
>>>>
>>>>
>>>>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php