On Feb 3, 3:12 pm, Michael Carriere <[email protected]> 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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to