On Feb 3, 2011, at 23:36, Sam Sherlock wrote: > On Feb 3, 2011, at 23:22, Ryan Schmidt wrote: > >> It's still unclear to me what the best way is to, for example, define >> additional variables that go with a particular record. My first impulse was >> to define an instance variable in the Model, but in light of the above, that >> doesn't seem correct. > > @ryan - the right thing takes some working out > > A user > name (full and secondname -- 2 fields) > username to login > hasMany published recipe's (table) > hasMany favorite recipe's () > > A recipee will have > One title (which is made into a slug) > One slug (an auto field) > hasMany->ingredients (table) > belongs to user
I understand that much; I'm not having any troubles defining columns in my database tables. What I am having trouble with is where to store variables that relate to their rows. For example, perhaps I have a table of hostnames and a Hostname model. I have a method that will find() some subset of them. Then I would like to connect to each of them using some network protocol. There is an object (not a model; just a PHP class loaded from the libs directory) that represents that connection. Where should I be storing that object? There will be multiple operations performed over that single connection once it's opened, so I would dislike to have to create the network connection anew in each method; that would be inefficient and wasteful of network resources. It shouldn't be the responsibility of a controller or a shell script to create this connection object; it's directly related to the Hostname model so it should be in that model. If the model were an object representing a hostname instance, then I might have had a private $_connection instance variable, and a public method getConnection(), which creates $this->_connection if it hasn't already been created (i.e. instantiates the connection object, which opens the network connection) and returns it. But since the model is merely a way to get an array of data, I'm unsure what technique I should be using. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
