2
votes

I'm trying to catch the information about PHP moreover I've got a project working with CakePHP but it's hard for me to get understand how is CakePHP working.

I created the database with table is Vkx and 4 columns is User_name , User_id , User_password, User_email I created in model a PHP file : User.php

The code: Model file : User.php

<?php

    class User extends AppModel{
         public $name = 'User';
    }
?>

Controller File : UsersController

class UsersController extends AppController{
     public function hello_user(){
          $user = $this->User->findByuser_id(1);
          $this->set('user',$user);
     }
}

Then in Views foder i created Users forder and "Hello_user.ctp" inside:

echo "hello , ".$user['User']['user_name']."!";

And the Error is:

Undefined index: User [APP\View\Users\hello_user.ctp, line 8]

1
Replace $user['User']['user_name'] with $user['user_name'] - Phantom
You can use debug($user) to inspect the variable, or install the Debug Kit plug-in - Álvaro González
Table name is Vkx ? - cornelb
yes ! and the columns's name are in the above - Xuandao

1 Answers

0
votes

Correct findByuser_id to findByUserId in this function

public function hello_user(){
       $user = $this->User->findByUserId(1);
       $this->set('user',$user);
       }