Wednesday, September 28, 2011

Re: Problem displaying output to view when using loadModel()

if you dont submit the id how can read() ever return the correct/
expected result?
thats what I ask myself when I look at your code


On 28 Sep., 17:08, dave <davespa...@gmail.com> wrote:
> Hi
>
> A newb having problems I'm afraid...
>
> I have a controller as follows:
>
> <?php
> class NdasController extends AppController {
>
>     var $name = 'Ndas';
>
>     function view($id = null) {
>                 $this->set('nda', $this->Nda->read());
>
>                 $this->loadModel('Post');
>                 $this->set('posts',$this->Post->find('all'));
>
>                 $this->loadModel('Registration');
>                 $this->set('registration', $this->Registration->read());
>     }
>
> }
>
> This uses table ndas, but I also want to access info from posts, and
> registrations...so I use loadModel.
>
> The view correctly shows a single nda details and all post details,
> but not the registration details (?). Here is the view:
>
> <div class="section">
>         <h2>Viewing POST info (where we fetched all data)</h2>
>         <p><?php
>                 foreach ($posts as $post):
>                         echo $post['Post']['title'];
>                 endforeach;
>         ?>
>
>         <h2>Viewing NDA for <?php echo $nda['Nda']['name']?></h2>
>         <div class="emailBox2">
>                 <p>Some fancy title referring to the NDA</p>
>                 <p><?php echo $nda['Nda']['name']?></p>
>                 <p><small>Created: <?php echo $nda['Nda']['created']?></small></p>
>                 ...
>         </div>
>
>         <h2>Viewing Registration for <?php echo $registration['Registration']
> ['name']?></h2>
>         <div class="emailBox2">
>                 <p>Some fancy title referring to the Registration</p>
>                 <p><?php echo $registration['Registration']['name']?></p>
>                 <p><small>Created: <?php echo $registration['Registration']
> ['created']?></small></p>
>                 ...
>         </div>
> </div>
>
> When I access all registration rows, it throws them out to the page
> correctly, so no problem retrieving data for all. The nda table and
> registration table are identical. What I really want to do is use this
> controller and view (NDAs) to access detail from the registration
> table. No errors are rendered, just that info from the registration
> row doesn't appear...
>
> Any help would be muchly appreciated. Apologies if not enough info,
> just ask. The models etc all ok as all work in other instances.
>
> Thanks
>
> Dave Burton

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

No comments: