maker1
maker1

Reputation: 5

Cakephp multiple forms in single view

On my edit view I have created 2 forms :

<?php echo $this->Form->create('EditPasswordUserForm')); ?>
<?php echo $this->Form->create('EditInfoUserForm')); ?>

Hence, I created 2 Models (2 files) :

class EditPasswordUserForm extends User
{

and

class EditInfoUserForm extends User
{

Controller User :

public function edit($slug)
{                   
    $this->loadModel('EditPasswordUserForm'); 
    $this->loadModel('EditInfoUserForm');
    $editpassword = $this->EditPasswordUserForm->findBySlug($slug);
    $editinfo = $this->EditInfoUserForm->findBySlug($slug);

    if(empty($this->data))
    {
        $this->request->data['EditPasswordUserForm'] = $editpassword['EditPasswordUserForm'];
        $this->request->data['EditInfoUserForm'] = $editinfo['EditInfoUserForm'];   
    }

}//end edit

I got this error message : Erreur: Class 'User' not found Fichier: C:\xampp\htdocs\projectmvc\app\Model\EditPasswordUserForm.php

Could you please help me.

Thank you Ligne: 4

Upvotes: 0

Views: 71

Answers (2)

q0re
q0re

Reputation: 1359

You don't need to create two classes.

You can just do:

echo $this->Form->create('User', array('action' => 'editPw'));
echo $this->Form->create('User', array('action' => 'editInfo'));

In your UsersController:

class UsersController extends AppController {
     public function editPw() {...}
     public function editInfo() {...}
}

Upvotes: 1

Supravat Mondal
Supravat Mondal

Reputation: 2594

You just import User model in your extend models, like as

App::import('Model', 'User');
class EditPasswordUserForm extends User
{
    //
}

and

App::import('Model', 'User');
class EditInfoUserForm extends User
{
  //
}

For best documentation read Behavior for Model Inheritance

Upvotes: 1

Related Questions