Re: Help for begginer.. problem with retrieving data from two models in one controller
Try use requestAction() and pass ur required paramameters through $pass array within the action The syntax is requestAction($fieldname/$controller_function, $pass=(array())); On 7/25/07, apadzik <[EMAIL PROTECTED]> wrote: > > > Hi! I'm a beginner in Cake and can't understand one thing, maybe you > more experienced people will know the solution:-) > So, I have two tables in db: products (id,name) and productsizes > (id,product_id,size); > Two models: Product, Productsize; > > product.php: > class Product extends AppModel > { > var $name = 'Product'; > var $hasMany = array('Productsize' => array( > 'className'=>'Productsize', > 'foreignKey'=>'product_id') > ); > } > > productsize.php: > class Productsize extends AppModel > { > var $name = 'Productsize'; > var $belongsTo = 'Product'; > } > > And products_controller looks like: > class ProductsController extends AppController > { > var $name = 'Products'; > var $uses = array('Product','Category','Productsize'); > var $layout = 'default'; > > function display($c_name) { > > $this->set('category_name',$c_name); > //this > is just > > $c_id=$this->Category->find('name=\''.$c_name.'\'','id'); > //for > retrivieng category > $this->set('products',$this->Product- > >findAllByCategoryId($c_id['Category']['id'])); //here i get all > data about products > $this->pageTitle = $c_name; > } > } > > And my question is: how do I retrieve data from productsizes? In > action "display" I want to show all products from one category and I > need to display the possible sizes for each one. How to do that in one > action? > > > > Controller: products_controller > > > > > -- Mithun Das --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Help for begginer.. problem with retrieving data from two models in one controller
Thank you very much Mike:-)) Your answer does of course make sense a lot;-)) Unfortunately, I checked your post after solving the problem, so maybe I will use your solution somewhere else;)) I finally did it by product_productsizes hABTM relation table (because products can have many sizes, as well as sizes can be related to many products) and in the view I retrieved the data like this: Name: Sizes: all i gotta do is create a dropdown list, cause now it just writes all the sizes one by one. thanks all for help! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Help for begginer.. problem with retrieving data from two models in one controller
On 26/07/07, apadzik <[EMAIL PROTECTED]> wrote: > > ? please help, it's driving me crazy >:-( ;-)) > I'll try. First of all, look at your relationships. Category has many Product Products has many ProductSize $product = $this->findAll(array('Product.category_id' => $c_name)); foreach($product as $p) { $size[$p['Product']['name']] = $this->Product->ProductSize->generateList(array('ProductSize.product_id' => $p['Product']['id']); } $this->set(compact('product', 'size')); Then in your view, you can go through each $product and get the information from it. To get the drop down list, use the $size array with the name of the product that you are looking at. Does that make sense? I hope it does, it does in my head anyway. If you want it clarified any more, let me know. Mike --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Help for begginer.. problem with retrieving data from two models in one controller
? please help, it's driving me crazy >:-( ;-)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Help for begginer.. problem with retrieving data from two models in one controller
maked On Jul 25, 5:37 pm, apadzik <[EMAIL PROTECTED]> wrote: > Hi! I'm a beginner in Cake and can't understand one thing, maybe you > more experienced people will know the solution:-) > So, I have two tables in db: products (id,name) and productsizes > (id,product_id,size); > Two models: Product, Productsize; > > product.php: > class Product extends AppModel > { > var $name = 'Product'; > var $hasMany = array('Productsize' => array( > 'className'=>'Productsize', > 'foreignKey'=>'product_id') > ); > > } > > productsize.php: > class Productsize extends AppModel > { > var $name = 'Productsize'; > var $belongsTo = 'Product'; > > } > > And products_controller looks like: > class ProductsController extends AppController > { > var $name = 'Products'; > var $uses = array('Product','Category','Productsize'); > var $layout = 'default'; > > function display($c_name) { > $this->set('category_name',$c_name); > //this > is just > $c_id=$this->Category->find('name=\''.$c_name.'\'','id'); > //for > retrivieng category > > $this->set('products',$this->Product->findAllByCategoryId($c_id['Category']['id'])); >//here i get all > > data about products > $this->pageTitle = $c_name; > } > > } > > And my question is: how do I retrieve data from productsizes? In > action "display" I want to show all products from one category and I > need to display the possible sizes for each one. How to do that in one > action? > > Controller: products_controller --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Help for begginer.. problem with retrieving data from two models in one controller
Thank's for answer and tip about the $c_id:) Ok, but how can I usa that generateList function if I don't have $product_id parameter? As I said I want to display all products from categories on one page, so my display action only handles category_id parameter, not product_id parameter. I tried the recursive way, it kinda worked but I still don't know how to use it;-) Let's say my view looks kinda like this: Name: Size: () //here I want to display a drop-down list of sizes that product is avaible in can't use the cause it gives me list of all sizes in the table don't know how to limit this $sizes thing to an appropriate product_id ;-( --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Help for begginer.. problem with retrieving data from two models in one controller
$size_list = $this->ProductSize- >generateList( array('ProductSize.product_id' => $product_id ); But a couple of notes. You can probably get what you want by just setting $this->Product->recursive = 1; before the findAllByCategoryId line. You can also improve the $c_id= line, to $c_id = $this->Category->field('id', array('name'=>$c_name)); This will get the id directly (no need for the ['Category']['id'] key), and will handle escaping the name (what if it has an actual " symbol in there?). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Help for begginer.. problem with retrieving data from two models in one controller
Hi! I'm a beginner in Cake and can't understand one thing, maybe you more experienced people will know the solution:-) So, I have two tables in db: products (id,name) and productsizes (id,product_id,size); Two models: Product, Productsize; product.php: class Product extends AppModel { var $name = 'Product'; var $hasMany = array('Productsize' => array( 'className'=>'Productsize', 'foreignKey'=>'product_id') ); } productsize.php: class Productsize extends AppModel { var $name = 'Productsize'; var $belongsTo = 'Product'; } And products_controller looks like: class ProductsController extends AppController { var $name = 'Products'; var $uses = array('Product','Category','Productsize'); var $layout = 'default'; function display($c_name) { $this->set('category_name',$c_name); //this is just $c_id=$this->Category->find('name=\''.$c_name.'\'','id'); //for retrivieng category $this->set('products',$this->Product- >findAllByCategoryId($c_id['Category']['id'])); //here i get all data about products $this->pageTitle = $c_name; } } And my question is: how do I retrieve data from productsizes? In action "display" I want to show all products from one category and I need to display the possible sizes for each one. How to do that in one action? Controller: products_controller --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---