Re: How to update data in several models in a single Web Service?

2014-03-09 Thread kdubya
Your statement the problem with CakePHP is that it only allows a 
controller to access its own corresponding model's data is just flat 
wrong. You can access additional models in a controller by simply adding 
the model name to the $uses variable in the controller class.

For example, the following allows you to access both the Recipe and User 
models in the Recipe controller (you can find more in the book 
at http://book.cakephp.org/2.0/en/controllers.html):

class RecipesController extends AppController {
public $uses = array('Recipe', 'User');
.
public function someAction() {
.
   $user = $this-User-find('first', array('conditions'=array('id', 
$userId)));
.
}
}

You can also achieve what you wish by using model associations. See:
 http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html

In your Table1 model class,  you define a $hasMany association with Table2, 
and in your Table2 model you define a $hasMany association with Table3. You 
can then access the lower level associations by doing a find() on Table1. 

You should also look at the Containable behavior. It makes it easy to 
define which models are retrieved when a find() is done. Containable is so 
handy I have put it in my AppModel class so all models have that behavior. 
See:
http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html

All of what you need to do this is described in the book and the examples. 
Study them. Try them. If you then have trouble, we'll answer your questions.

Ken

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to update data in several models in a single Web Service?

2014-03-08 Thread Sam
There are 3 tables in my database. Table1 has a one-to-many relationship to 
Table2. Table2 has a one-to-many relationship to Table3. I would like to 
write a web service API that allows the user to add rows to all 3 tables at 
the same time. The problem with CakePHP is that it only allows a controller 
to access its own corresponding model's data. How can a controller access 
other models? What is the best practices for CakePHP for a single 
controller to access other models? For my case in particular, which table 
should I use? Will Table1 be a good start since it is the parent to the 
other tables?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.