Bonjour,
Je travaille sur cakephp, je suis entrain de faire un formulaire d'ajout pour entrer un utilisateur :
J'ai une table nommé "user_tbl" avec mes différents champs créé ci dessous :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 CREATE TABLE user_tbl( user_id INT(10), user_name VARCHAR(50), user_firstname VARCHAR(50), user_adress VARCHAR(50), user_mail VARCHAR(50), user_phone_number VARCHAR(15), user_password VARCHAR(100), user_status VARCHAR(50), CONSTRAINT pk_user_id PRIMARY KEY (user_id) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Problème, quand je souhaite sauvegarder mes données, j'ai une erreur : Call to a member function save() on a non-object
Dans mon Controller j'ai mon fichier : UsersController.php
Dans ma View/user_tbl j'ai mon ficher : add.ctp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 <?php class UsersController extends AppController { public $name = 'user_tbl'; public function add(){ if ($this->request->is('post')){ if ($this->User->save($this->request->data)){ $this->Session->setFlash('User was added.'); $this->redirect(array('action' => 'index')); }else{ $this->Session->setFlash('Unable to add user. Please, try again.'); } } } } ?>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 <h2>Add New User</h2> <!-- link to add new users page --> <div class='upper-right-opt'> <?php echo $this->Html->link( 'List Users', array( 'action' => 'index' ) ); ?> </div> <?php echo $this->Form->create('User'); echo $this->Form->input('user_name'); echo $this->Form->input('user_firstname'); echo $this->Form->input('user_adress'); echo $this->Form->input('user_mail'); echo $this->Form->input('user_phone_number'); echo $this->Form->input('user_password', array('type'=>'password')); echo $this->Form->input('user_status'); echo $this->Form->end('Submit'); ?>
Partager