What you are doing is nearly right. If you read the online book you'll see that
the second parameter in the read function is the id of the record you want to
retrieve: http://book.cakephp.org/view/1029/read
If you want to retrieve all records, use $this->set('state',
$this->Home->State->find('all')); (although arguably your variable name should
be $states, not $state). This section is worth a read:
http://book.cakephp.org/view/1017/Retrieving-Your-Data
Jeremy Burns
Class Outfit
http://www.classoutfit.com
Jeremy Burns
Class Outfit
http://www.classoutfit.com
Jeremy Burns
Class Outfit
http://www.classoutfit.com
On 17 Oct 2011, at 11:01, anjith wrote:
> Hi,
>
> I am developing an application using cake bake commands, I need to
> display various models data in the home page. So i created a
> controller fro that purpose but unable to find how to get data of
> various models from that controller.
>
>
>
> where in home model i declared as follows
>
> <?php
> class Home extends AppModel {
> var $name = 'State';
> var $displayField = 'name';
> //The Associations below have been created with all possible keys,
> those that are not needed can be removed
> var $hasMany = array(
> 'State' => array(
> 'className' => 'States',
>
> )
> );
> }
>
> ?>
>
>
> As i am new i dont know whether this type of coding is correct or not.
> If not can any one suggest me correct way of doing it.
>
> I tired to access data using following code
>
> $this->set('state', $this->Home->State->read(null, 1));
>
> I am able to get only one reccord actuall i need to fetch all the
> records. I tired few other methods of model like find but unable to
> fulfil my requirement. How can i fetch all the records of another
> model from a controller.
>
> Regards,
> Anjith
>
> --
> 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
--
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