Re: Understanding the M in MVC?

2011-02-04 Thread Jeremy Burns | Class Outfit
Shell scripts are beyond my experience, so can't contribute to that one. Sounds 
like this ought to go in a component though, if you want to do it from multiple 
controllers.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 4 Feb 2011, at 07:45, Ryan Schmidt wrote:

 
 On Feb 4, 2011, at 01:13, Jeremy Burns | Class Outfit wrote:
 
 Create a function in your controller that firstly creates the connection 
 object. Then have the function get the data from the model, which returns an 
 array to the controller and is stored in a variable in the controller. Now 
 parse that array running your controller/component function against your 
 connection object.
 
 I thought that might be the answer... but what if I not only need to do this 
 from a controller (multiple controllers), but also from shell scripts (in 
 APP/vendor/shells)?
 
 
 -- 
 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
 cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
 http://groups.google.com/group/cake-php

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 3, 3:12 pm, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!

 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other things, 
 but I seem to be having a difficult time in the way I should be understanding 
 the M in MVC. I've done enough web development in the past to be familiar 
 with PHP, but more recently I've worked in object-oriented, compiled 
 languages, as well as a few web tools built with Django. I could just give up 
 and do whatever works, but I feel like there's something powerful to be 
 taken advantage of here, and I hope you guys can help!

 How magical is the find() function?

As magical as you want it to be - or not as the case may be.

 Should I be able to run one exhaustive query and get back all the nested data 
 that I need for a View to spit out?

you should be able to call whatever model method you want from a
controller and pass it to the view, yes.

 I guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with the 
 Set class, right?) and then passing that to the view to be displayed?

That's my personal preference.

ie. example controller code:

$posts = $this-Post-find('all', compact('conditions'));
$uids = Set::extract($posts, '/Post/user_id');
$authors = $this-Post-User-find('list', array('conditions' =
array('id' = $uids));
$this-set(compact('posts', 'authors'));


 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

containable has its uses, decide based on the sql it generates.


 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once?

don't know what you mean.

 Or at least in the case of working with a Model.

 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()?

why would you create an alias for existing simple find calls?

 Better yet, how do you operate on 'instances' of your data as defined by your 
 model?

instances of your data are arrays - you treat them as arrays.


 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.

try and keep it to one question per thread and you're more likely to
get answers that help.

AD

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 4, 8:13 am, Jeremy Burns | Class Outfit
jeremybu...@classoutfit.com wrote:
 Create a function in your controller that firstly creates the connection 
 object.

Holy MVC sacrilege batman. I hope you meant to say model.

$stuff = $this-Model-somefunction()

is about as far as a controller should go

AD

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 4, 8:45 am, Ryan Schmidt google-2...@ryandesign.com wrote:
 On Feb 4, 2011, at 01:13, Jeremy Burns | Class Outfit wrote:

  Create a function in your controller that firstly creates the connection 
  object. Then have the function get the data from the model, which returns 
  an array to the controller and is stored in a variable in the controller. 
  Now parse that array running your controller/component function against 
  your connection object.

 I thought that might be the answer... but what if I not only need to do this 
 from a controller (multiple controllers), but also from shell scripts (in 
 APP/vendor/shells)?

Fat models dictate that only models should eat datasources, and
controllers and shells should only feed models params

AD

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-04 Thread Jeremy Burns | Class Outfit
I take your point, and I'll admit that my controllers are often too fat. I call 
model functions as much as possible, but find myself dipping back into the 
controller when I need to use the Auth component, the Session, redirect and so 
on (although I do collect as much info as I can and pass it into the model 
function when possible). Am I alone in that?

What is the principle behind fat model/skinny controller; is it performance, 
efficiency, code cleanliness?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 4 Feb 2011, at 09:09, AD7six wrote:

 
 
 On Feb 4, 8:13 am, Jeremy Burns | Class Outfit
 jeremybu...@classoutfit.com wrote:
 Create a function in your controller that firstly creates the connection 
 object.
 
 Holy MVC sacrilege batman. I hope you meant to say model.
 
 $stuff = $this-Model-somefunction()
 
 is about as far as a controller should go
 
 AD
 
 -- 
 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
 cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
 http://groups.google.com/group/cake-php

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-04 Thread AD7six


On Feb 4, 10:29 am, Jeremy Burns | Class Outfit
jeremybu...@classoutfit.com wrote:
 I take your point, and I'll admit that my controllers are often too fat. I 
 call model functions as much as possible, but find myself dipping back into 
 the controller when I need to use the Auth component, the Session, redirect 
 and so on (although I do collect as much info as I can and pass it into the 
 model function when possible). Am I alone in that?

 What is the principle behind fat model/skinny controller; is it performance, 
 efficiency, code cleanliness?

Consider writing some functionality in your controller and /then/
needing it in a shell such as Ryan's situation. If you use models as
intended it's trivial to solve, if not you've got the pending question
how do I use that controller from this shell? which is a question
that shouldn't ever exist.

It's the same problem/question if you need the same functionality in
two or more controllers, but there you're likely to either cheat and
use requestAction or worse needless inheritance/a component. Neither
of which help with the shell conundrum which imo is quite common as a
project scales and you find you need to do more and more things via
shell scripts.

AD

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Understanding the M in MVC?

2011-02-03 Thread Michael Carriere
Hello everyone!

When recently approached to do some web development for a game whose code base 
was in dire need of a rewrite, I was determined on finding a stable, community 
supported framework to help speed up the process. I appreciate Cake's file 
organization, the way layouts are controlled, among other things, but I seem to 
be having a difficult time in the way I should be understanding the M in MVC. 
I've done enough web development in the past to be familiar with PHP, but more 
recently I've worked in object-oriented, compiled languages, as well as a few 
web tools built with Django. I could just give up and do whatever works, but 
I feel like there's something powerful to be taken advantage of here, and I 
hope you guys can help!


How magical is the find() function? Should I be able to run one exhaustive 
query and get back all the nested data that I need for a View to spit out? I 
guess a better question would be: do you find yourself calling find() on 
different sets of data, packaging them together yourself (presumably with the 
Set class, right?) and then passing that to the view to be displayed?

I have some data that is loosely related, and while I can manage to get at all 
of it in one query, it requires me using Containable, and dropping 5-6 
associations in. That just seems quite inefficient for me. (Maybe it's not?)

Coming from many OO languages, after you define a class, you instantiate it as 
you want to work with an individual object, play with it as you want, and throw 
it out. Correct me if I'm wrong, but it seems that MVC's approach is more 
geared towards operating on all the data at once? Or at least in the case of 
working with a Model.

This leads to some confusion for me, because the majority of the instances 
where I need to access data, it's of a small subset of the data I'm storing in 
the DB for my model. My webgame has Buildings in it, which belong to a User's 
Village. Sometimes I want to grab information from a specific Building, and 
other times I want to grab only the specific Buildings of a Village. Is it 
proper to be define a function within the model that grabs or manipulates data 
based on this, like $this-Village-getBuildingsByVillageId()? Better yet, how 
do you operate on 'instances' of your data as defined by your model?

I may have some more questions later, but I'll start this thread with these two 
(albeit loaded) questions.

Any help is appreciated, thank you!

- Michael


-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-03 Thread andy_the ultimate baker
will u please make it short and approachable to ur point,
becouse no one is having to read a long theses of ur query on the
work
so please make it shor and come in pints, so it would be fine to give
u answer

regards
andy

On Feb 3, 7:12 pm, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!

 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other things, 
 but I seem to be having a difficult time in the way I should be understanding 
 the M in MVC. I've done enough web development in the past to be familiar 
 with PHP, but more recently I've worked in object-oriented, compiled 
 languages, as well as a few web tools built with Django. I could just give up 
 and do whatever works, but I feel like there's something powerful to be 
 taken advantage of here, and I hope you guys can help!

 How magical is the find() function? Should I be able to run one exhaustive 
 query and get back all the nested data that I need for a View to spit out? I 
 guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with the 
 Set class, right?) and then passing that to the view to be displayed?

 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once? Or at least in the 
 case of working with a Model.

 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?

 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.

 Any help is appreciated, thank you!

 - Michael

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-03 Thread ibejohn818
Model-View-Controller

Model is data.

Cakephp's model layer uses a programming technique called ORM (Object-
Relational-Mapping)
http://en.wikipedia.org/wiki/Object-relational_mapping

If you are familiar with python then it would be comparable to
sqlalchemy but just not as many features and configuration options.

On Feb 3, 6:12 am, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!

 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other things, 
 but I seem to be having a difficult time in the way I should be understanding 
 the M in MVC. I've done enough web development in the past to be familiar 
 with PHP, but more recently I've worked in object-oriented, compiled 
 languages, as well as a few web tools built with Django. I could just give up 
 and do whatever works, but I feel like there's something powerful to be 
 taken advantage of here, and I hope you guys can help!

 How magical is the find() function? Should I be able to run one exhaustive 
 query and get back all the nested data that I need for a View to spit out? I 
 guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with the 
 Set class, right?) and then passing that to the view to be displayed?

 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once? Or at least in the 
 case of working with a Model.

 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?

 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.

 Any help is appreciated, thank you!

 - Michael

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-03 Thread Jeremy Burns | Class Outfit
Michael

I find the model structure very flexible. I generally set recursive to -1 (this 
means my starting point is this record and none of its associations), and use 
the Containable behaviour; both of these are set in my custom app_model.php 
file, which means they apply to all models by default.

Before even touching a model I thrash out my actual data model as best as I can 
and then build my models around it starting with the associations and 
validation first. I like to make my data tightly integrated so that I can rely 
on relationships, but there are always occasions when a bit of data just 
doesn't link with another, but I know I am going to have to tie them together. 
I also build some generic find queries that I know I will use many times - 
these tend to be fully featured containing all the key related data for a given 
'id'. Saves me building the same query over and over again and it's easier to 
maintain.

When something doesn't fit I and I need to tie unrelated data together (which 
is rare) I do one of three things:
- Store the unrelated data in the session, if it's small and appropriate, or 
even in a config file.
- Use loadModel to make it available to 'this' controller, perform a find and 
store the result in an array for later manipulation = perhaps in the model.
- Use the 'joins' elements to construct my own query (I prefer this to using 
'query'). I also fall back on this method if I want to restrict a record set by 
a condition on one of its relationships using inner joins (Contain uses outer 
joins).

When models are associated correctly you can indeed daisy chain across them to 
call an action on a distant model.

Not sure that totally answers your question, but I hope it gets the ball 
rolling.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 4 Feb 2011, at 05:02, andy_the ultimate baker wrote:

 will u please make it short and approachable to ur point,
 becouse no one is having to read a long theses of ur query on the
 work
 so please make it shor and come in pints, so it would be fine to give
 u answer
 
 regards
 andy
 
 On Feb 3, 7:12 pm, Michael Carriere m...@zapdot.com wrote:
 Hello everyone!
 
 When recently approached to do some web development for a game whose code 
 base was in dire need of a rewrite, I was determined on finding a stable, 
 community supported framework to help speed up the process. I appreciate 
 Cake's file organization, the way layouts are controlled, among other 
 things, but I seem to be having a difficult time in the way I should be 
 understanding the M in MVC. I've done enough web development in the past 
 to be familiar with PHP, but more recently I've worked in object-oriented, 
 compiled languages, as well as a few web tools built with Django. I could 
 just give up and do whatever works, but I feel like there's something 
 powerful to be taken advantage of here, and I hope you guys can help!
 
 How magical is the find() function? Should I be able to run one exhaustive 
 query and get back all the nested data that I need for a View to spit out? I 
 guess a better question would be: do you find yourself calling find() on 
 different sets of data, packaging them together yourself (presumably with 
 the Set class, right?) and then passing that to the view to be displayed?
 
 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)
 
 Coming from many OO languages, after you define a class, you instantiate it 
 as you want to work with an individual object, play with it as you want, and 
 throw it out. Correct me if I'm wrong, but it seems that MVC's approach is 
 more geared towards operating on all the data at once? Or at least in the 
 case of working with a Model.
 
 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?
 
 I may have some more questions later, but I'll start this thread with these 
 two (albeit loaded) questions.
 
 Any help is appreciated, thank you!
 
 - Michael
 
 -- 
 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
 cake-php+unsubscr

Re: Understanding the M in MVC?

2011-02-03 Thread Ryan Schmidt
Welcome!


On Feb 3, 2011, at 08:12, Michael Carriere wrote:

   • How magical is the find() function? Should I be able to run one 
 exhaustive query and get back all the nested data that I need for a View to 
 spit out? I guess a better question would be: do you find yourself calling 
 find() on different sets of data, packaging them together yourself 
 (presumably with the Set class, right?) and then passing that to the view to 
 be displayed?
 
 I have some data that is loosely related, and while I can manage to get at 
 all of it in one query, it requires me using Containable, and dropping 5-6 
 associations in. That just seems quite inefficient for me. (Maybe it's not?)

Based on what i've read, Containable seems like the best answer to your 
question. Without Containable, you can specify a recursion level, but that's 
it. Much better to use Containable to say exactly which items from which levels 
you want to receive, and it figures out the rest.


   • Coming from many OO languages, after you define a class, you 
 instantiate it as you want to work with an individual object, play with it as 
 you want, and throw it out. Correct me if I'm wrong, but it seems that MVC's 
 approach is more geared towards operating on all the data at once? Or at 
 least in the case of working with a Model.
 
 This leads to some confusion for me, because the majority of the instances 
 where I need to access data, it's of a small subset of the data I'm storing 
 in the DB for my model. My webgame has Buildings in it, which belong to a 
 User's Village. Sometimes I want to grab information from a specific 
 Building, and other times I want to grab only the specific Buildings of a 
 Village. Is it proper to be define a function within the model that grabs or 
 manipulates data based on this, like 
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on 
 'instances' of your data as defined by your model?

I have questions along these lines too.

It seems to me that the Model is there to let you access your data, usually 
from a database table (though it doesn't have to be). So a Model does not 
represent an instance of something from your database table*; rather, it is an 
interface to retrieve data from it -- be that a single record or a set of 
records, and possibly, depending on recursion or Containable, related records. 
This data is usually returned by the find() method, and is in the form of a 
rather nested array. You receive the array from the Model (in your Controller, 
or in a Shell perhaps), loop over the records, and do whatever you want with 
them.

Yes, it seems correct to define additional methods in your Model that return 
data from particular queries that are of use to you. It seems to me that if 
your method is getBuildingsByVillageId(), then it would be in the Building 
model (because it primarily returns information about Buildings), not in the 
Village model, though I'm not clear what the guidance is on this topic.

*This is complicated by the fact that in some cases you can get data from a 
particular row to live in the Model -- to be the active record -- and you can 
page through all the records in your data set this way. I'm not certain yet 
whether this is just an alternate way to access the same data that's just more 
comfortable to some people, or whether there are cases when this is the only 
way to do it.

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.




-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-03 Thread Sam Sherlock
M = Model
Interaction with data  stored in a database or via a datasource (eg the
twitter example)

Dropping assocs on the fly is easier than building them on the fly
You set the associations as they would generally be needed between models
within your app

Your setting you app up to be able to retrive exactly what you require with
the least amount of controller and view coding
setting up models in the right way (associations, behaviours, validation,
custom find methods) means you can use and reuse
these models in versatile ways within your app

a lean app with fat models;

that custom model method really depends on the complexity of the find you
are using; if you can then additionally make it serve other purposes
elsewhere - eg pass it params to have it return data for different
circumstances

and what Jeremy says :)
and now Ryan has also answered

@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

Ingredients
  Name



- S



On 4 February 2011 05:02, andy_the ultimate baker 
anandghaywankar...@gmail.com wrote:

 will u please make it short and approachable to ur point,
 becouse no one is having to read a long theses of ur query on the
 work
 so please make it shor and come in pints, so it would be fine to give
 u answer

 regards
 andy

 On Feb 3, 7:12 pm, Michael Carriere m...@zapdot.com wrote:
  Hello everyone!
 
  When recently approached to do some web development for a game whose code
 base was in dire need of a rewrite, I was determined on finding a stable,
 community supported framework to help speed up the process. I appreciate
 Cake's file organization, the way layouts are controlled, among other
 things, but I seem to be having a difficult time in the way I should be
 understanding the M in MVC. I've done enough web development in the past
 to be familiar with PHP, but more recently I've worked in object-oriented,
 compiled languages, as well as a few web tools built with Django. I could
 just give up and do whatever works, but I feel like there's something
 powerful to be taken advantage of here, and I hope you guys can help!
 
  How magical is the find() function? Should I be able to run one
 exhaustive query and get back all the nested data that I need for a View to
 spit out? I guess a better question would be: do you find yourself calling
 find() on different sets of data, packaging them together yourself
 (presumably with the Set class, right?) and then passing that to the view to
 be displayed?
 
  I have some data that is loosely related, and while I can manage to get
 at all of it in one query, it requires me using Containable, and dropping
 5-6 associations in. That just seems quite inefficient for me. (Maybe it's
 not?)
 
  Coming from many OO languages, after you define a class, you instantiate
 it as you want to work with an individual object, play with it as you want,
 and throw it out. Correct me if I'm wrong, but it seems that MVC's approach
 is more geared towards operating on all the data at once? Or at least in the
 case of working with a Model.
 
  This leads to some confusion for me, because the majority of the
 instances where I need to access data, it's of a small subset of the data
 I'm storing in the DB for my model. My webgame has Buildings in it, which
 belong to a User's Village. Sometimes I want to grab information from a
 specific Building, and other times I want to grab only the specific
 Buildings of a Village. Is it proper to be define a function within the
 model that grabs or manipulates data based on this, like
 $this-Village-getBuildingsByVillageId()? Better yet, how do you operate on
 'instances' of your data as defined by your model?
 
  I may have some more questions later, but I'll start this thread with
 these two (albeit loaded) questions.
 
  Any help is appreciated, thank you!
 
  - Michael

 --
 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
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php


-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-03 Thread Ryan Schmidt

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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-03 Thread Jeremy Burns | Class Outfit
Create a function in your controller that firstly creates the connection 
object. Then have the function get the data from the model, which returns an 
array to the controller and is stored in a variable in the controller. Now 
parse that array running your controller/component function against your 
connection object.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 4 Feb 2011, at 07:06, Ryan Schmidt wrote:

 
 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
 cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
 http://groups.google.com/group/cake-php

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Understanding the M in MVC?

2011-02-03 Thread Ryan Schmidt

On Feb 4, 2011, at 01:13, Jeremy Burns | Class Outfit wrote:

 Create a function in your controller that firstly creates the connection 
 object. Then have the function get the data from the model, which returns an 
 array to the controller and is stored in a variable in the controller. Now 
 parse that array running your controller/component function against your 
 connection object.

I thought that might be the answer... but what if I not only need to do this 
from a controller (multiple controllers), but also from shell scripts (in 
APP/vendor/shells)?


-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php