Re: a bit confused (n00b warning)
OK, so instead of doing it the CakePHP way, I did it my way: App::Import('Model', 'Modelname'); I read that: var $uses = array('Model1', 'Model2', 'Model3'); is slow. I leave it to the pros. So now I have my original 3 tables and not the HABTM. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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: a bit confused (n00b warning)
On Jun 7, 9:18 am, Joel Perras <[EMAIL PROTECTED]> wrote: > Ok, I'll attempt to re-iterate what you are attempting to do, because > it is not completely clear to me: > > 1) You want to be able to 'add items to an apartment', where items <- > HABTM-> apartments. > 2) This should be accomplished through an HTML select drop-down, which > would be populated with all the items contained within your items > table. Well, like I said, I'm not sure if that is the correct way to do it. > ** The above point seems odd to me, since I'm guessing you would like > to have the ability to input many different items (of various > quantities) for each apartment. Yes, that exactly what I'm trying to do. So at first, I had three tables: 1. items; 2. units; 3. inventory; The inventory table holds records with unit, item, and amount. So then I can run a query where unit = ? and show everything in a certain unit. Seems the most straight forward way to go about it. Then I realized CakePHP is much more structured than other "frameworks" I've used, and I wanted to use what methods CakePHP provided me with. Thanks for your advice. BTW, there's no rush on this one. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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: a bit confused (n00b warning)
Ok, I'll attempt to re-iterate what you are attempting to do, because it is not completely clear to me: 1) You want to be able to 'add items to an apartment', where items <- HABTM-> apartments. 2) This should be accomplished through an HTML select drop-down, which would be populated with all the items contained within your items table. ** The above point seems odd to me, since I'm guessing you would like to have the ability to input many different items (of various quantities) for each apartment. This can also be accomplished, but it's a question of what your design/architecture requires. If this is anywhere near what you are attempting to accomplish, let me know. I just don't want to help you solve a problem you don't have. -Joel. P.S. Something I noticed from your first post: the most likely reason that CakePHP couldn't find the 'inventory' table was that it wasn't following the CakePHP conventions (which can be overrided, of course). If your table name was 'inventories', then the Inflector would have been able to singularize the name, and find the InventoryController, and the 'inventories' views.. On Jun 6, 2:36 am, winter <[EMAIL PROTECTED]> wrote: > Thanks Joel, > > That sounds nice. I guess maybe I'm not being so clear and perhaps I > am missing something. > > I'm trying to make a form to fill the join table. You see, a > unit(apartment) has many items. For example Apartment A has 5 glasses > and Apartment B has 10 glasses. > > Using plain PHP, I'd query my item table and use that data in a select > element on my html form. The form would not allow you to set unit_id. > I'd use a hidden field which is the value passed when clicking on a > "add items to this apartment" link. When the form is submitted, > unit_id, item_id, and amount are inserted into my inventory table. > > Now I have this join table, which seems like it's what I want. Though, > perhaps it really isn't. Because I'm not sure if I can make a view for > it according to cakephp convention. > > Cakephp seems to have many fantastic features for rapid app > development. So I'd like to understand it. Things are becoming clearer > after reading many blogs and docs. If you think there is something I > should read, please point me to it. > > Thanks again! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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: a bit confused (n00b warning)
Thanks Joel, That sounds nice. I guess maybe I'm not being so clear and perhaps I am missing something. I'm trying to make a form to fill the join table. You see, a unit(apartment) has many items. For example Apartment A has 5 glasses and Apartment B has 10 glasses. Using plain PHP, I'd query my item table and use that data in a select element on my html form. The form would not allow you to set unit_id. I'd use a hidden field which is the value passed when clicking on a "add items to this apartment" link. When the form is submitted, unit_id, item_id, and amount are inserted into my inventory table. Now I have this join table, which seems like it's what I want. Though, perhaps it really isn't. Because I'm not sure if I can make a view for it according to cakephp convention. Cakephp seems to have many fantastic features for rapid app development. So I'd like to understand it. Things are becoming clearer after reading many blogs and docs. If you think there is something I should read, please point me to it. Thanks again! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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: a bit confused (n00b warning)
Hi winter, If you have a field called 'name' or 'title' in the Item table (which I'm guessing is the case from the schema you gave above), try using: $items = $this->Item->find('list'); $this->set(compact('items'));. If your field isn't called 'name' or 'title', then you can set the $displayField variable in the Item model for whatever field name you use to identify the items. This should be enough for cake to automagically populate the form input on your view pages (if you are using the form helper, of course). -Joel. On Jun 5, 11:41 pm, winter <[EMAIL PROTECTED]> wrote: > Thanks Chris. I read your reply and went over it again this morning > and managed to get that association to work. The bit that is still > stumping me is the html select. I still can't do: $this->set('items', > $this->Item->findAll()); in my add() function in units_controller.php. > I want to pass all the items to the add view and have them populate an > html select. Perhaps there is a built-in cake method for doing this. > Am I going about it wrong? Thanks for your help. It's much appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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: a bit confused (n00b warning)
Thanks Chris. I read your reply and went over it again this morning and managed to get that association to work. The bit that is still stumping me is the html select. I still can't do: $this->set('items', $this->Item->findAll()); in my add() function in units_controller.php. I want to pass all the items to the add view and have them populate an html select. Perhaps there is a built-in cake method for doing this. Am I going about it wrong? Thanks for your help. It's much appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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: a bit confused (n00b warning)
On Thu, Jun 5, 2008 at 8:00 AM, winter <[EMAIL PROTECTED]> wrote: > > Everything was going fin untill I wanted to put some html select tags > on the add view for the pivots table. The docs don't say how I can > access data from another model - $this->set('units', $unit->Unit- >>findAll());. Of course it's not $this. I read the docs some more and > found out about ascociations. This is where hair begins to fall out. > > I've been making DB apps for quite some time now and never used > something like this. It reminds me of MS Access. Ugh. Do I really need > to set this up? Will it be flexible in the end? What ascociation do I > use? I read about the hasAndBelongsToMany and the required join table. > It sounds like it's just what I want to do. Is it? Can I just Item- >>findAll() and pass the data to the view and put it in the html > select? > Here's what I would try: 1) rename your 'pivots' table and change it to be named 'items_units' and drop the ID field as you don't need it 2) create your HABTM relationship (instructions in the manual) Then you can access info like this (these are only examples) $results = $this->Item->find('all') ==> gives you all Items and their associated units $results = $this->Item->Unit->find('all', ) => gives you all units that match your conditions Hope that helps (and I hope I did that right :) ) -- Chris Hartjes Internet Loudmouth Motto for 2008: "Moving from herding elephants to handling snakes..." @TheKeyBoard: http://www.littlehart.net/atthekeyboard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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 -~--~~~~--~~--~--~---
a bit confused (n00b warning)
Hi all, A bit irrelevant, but I'm using: cakephp 1.2.7119 RC1 sqlite 2.8.17 PHP Version 5.1.2 on linux kernel version 2.6.15 I've made exactly one simple app using cakephp. That was only to input some records to a single table. I thought it was so easy that I'd use it for my next project, which is amazingly simple: an inventory I have three tables: unit - id, title, code items - id, title, code inventory - id, unit_id, item_id Each unit(apartment) has some items, which is where the inventory table comes it. I had to rename my inventory to pivots because somehow inventory might be a reserved word or something. It will not find the controller if it's named inventory. Now I have: CREATE TABLE units(id INTEGER PRIMARY KEY, code TEXT, title TEXT); CREATE TABLE items(id INTEGER PRIMARY KEY, code TEXT, title TEXT); CREATE TABLE pivots(id INTEGER PRIMARY KEY, unit_id INTEGER, item_id INTEGER); Everything was going fin untill I wanted to put some html select tags on the add view for the pivots table. The docs don't say how I can access data from another model - $this->set('units', $unit->Unit- >findAll());. Of course it's not $this. I read the docs some more and found out about ascociations. This is where hair begins to fall out. I've been making DB apps for quite some time now and never used something like this. It reminds me of MS Access. Ugh. Do I really need to set this up? Will it be flexible in the end? What ascociation do I use? I read about the hasAndBelongsToMany and the required join table. It sounds like it's just what I want to do. Is it? Can I just Item- >findAll() and pass the data to the view and put it in the html select? Sorry for the stream of questions. Thanks for the advice! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" 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 -~--~~~~--~~--~--~---