Cakephp Passing Information Between Controllers

Asked

Viewed 448 times

0

How do I pass information between two controllers, example:

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

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

  1. How do I pass this information between controllers
  2. How do I select the user id logged in to the system
  3. What is the right way to do this update

1 answer

0


In the Cookbook you can see a method called loadModel(), with it is possible you use the Model of users within your 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 done the relationship correctly between the tables and created the Models correctly you can use the sequinte to manipulate the related data

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

To get user data logged in to cakephp you can use the section or the Component Auth

Auth

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

Session

$this->Session->read('User.id');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.