0
I’m having an error passing the data from the database to the view, only the code is pretty much the same as the one I have, and it works correctly. The Array with the data is also being sent to the view, but the User
in $users['User']['...'];
causes this error. How to solve this problem?
Controller
public function admin_mod_password(){
$this->loadModel('User');
$users = $this->User->find('all');
$this->set('users', $users);
$this->layout='admin_index';
}
View
<h2>Modificar a Password</h2>
<br>
<table>
<tr>
<td>
<p>Nome de Administrador: </p>
</td>
<td>
<?php echo $users['User']['username']; ?>
</td>
</tr>
<tr>
<td>
<p>Password actual: </p>
</td>
<td>
<?php echo $users['User']['password'];?>
</td>
</tr>
Model
<?php
App::uses('AppModel', 'Model');
//http://book.cakephp.org/2.0/pt/tutorials-and-examples/blog-auth-example/auth.html
class User extends AppModel {
public $useTable = 'users';
public $name = 'User';
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
)
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
)
),
'role' => array(
'valid' => array(
'rule' => array('inList', array('admin', 'author')),
'message' => 'Please enter a valid role',
'allowEmpty' => false
)
)
);
}
?>
var_dump($users)
array (size=1)
0 =>
array (size=1)
'User' =>
array (size=7)
'id' => string '1' (length=1)
'username' => string 'teste' (length=5)
'password' => string 'teste' (length=5)
'created' => string '0000-00-00 00:00:00' (length=19)
'modified' => string '0000-00-00 00:00:00' (length=19)
'role' => string 'admin' (length=5)
'user_id' => string '1' (length=1)
Post the result of
var_dump()
of the variable$users
– gmsantos
@gmsantos I’ve already put.
– SunT