CakePHP Reviewing Information Between Controllers

0

How do I pass information between two controllers, for example:

I have in my database two tables, one of users and another of books, there I select a book that is in the books table, I get your id and I have to update this information in the user table ..

I have two controllers, one of users and one of books, I have to pass the book id to the user controller ..

  • How do I pass this information between controllers
  • How do I select the user id logged in the system
  • What is the correct way to do this update
  • asked by anonymous 23.03.2015 / 15:54

    1 answer

    0

    In the cookbook you can see a method called loadModel() , with it you can use Model of users within your < in> controller books.

    Example:

    $this->loadModel('User');
    $users = $this->User->find('all');
    

    If you want to load a specific data from another Model you can use:

    $this->loadModel('Livro', 2);
    $livro = $this->Livro->read();
    

    If you have correctly made the relationship between the tables and created the Models correctly you can use the following to manipulate the related data

    $users = $this->User->Livro->find('all');
    $livros = $this->Livro->User->find('all');
    

    To get the user data logged in the cakephp you can use the component Auth section

    Auth

    $this->Auth->user('id');
    

    Session

    $this->Session->read('User.id');
    
        
    23.03.2015 / 16:08