On May 10, 5:02 pm, Ming <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I am new to cake and I have several questions. :)
>
> >From the blog tutorial:
> 1)
> <?php
> //AppModel gives you all of Cake's Model functionality
> class Post extends AppModel
> {
> // Its always good practice to include this variable.
> var $name = 'Post';
>
> Is this var ($name) mandatory? In view, I have <?php echo $row['Post']
> ['id']; ?>. Does ['Post'] here refer to the $name var?
As I understand it, it is mandatory of you're using PHP 4, optional
but good practice in PHP5.
> 2) In the controller, I have $this->set('posts',$this->Post->findAll());
> Where does this 'posts' come from?
It is arbitrary - it could just as well be "$this->set('FooBar',$this-
>Post->findAll())" - '$posts' is the variable that will be available
in your View - it will contain the value of the second argument to the
'set' function, in this case the return value of $this->Post-
>findAll().
>Does the Post in $this->Post refer to the data model named Post or the var
>$name with name Post?
It refers to the model which is referenced from your controllers by
the name you assign to it - in this case, 'Post'
Always adhere to the naming conventions to make your life better.
> 3)
> In view, I have <?php echo $row['Post']['id']; ?>
>
> The question is the same, does the Post here refer to the data model
> named Post or the var $name with name Post?
The view doesn't have access to the model directly. The controller
can query a model and pass this information on to your view. Here,
'Post' refers to an array element ($row[]) which (following naming
conventions) was given the name of the model that the information came
from.
Since your questions relate to the "var $name = " in your models, I'd
say don't worry about the existential distinction between a model and
it's name. Once you get your models set up, you'll never look at them
again anyway. If you follow naming conventions for your tables,
models, etc, Cake will always know what you're referring to.
>
> Thanks a lot
>
> Ming
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---