Please use print_r($title) so that you can get is there any variable named title or not if it gives error again please heck the variable assignment on the $this->set in the controller.
On Thu, Aug 6, 2009 at 9:52 PM, jburns <[email protected]> wrote: > > Hi - I am new to CakePHP and finding my way around. > > I have used bake to create model/view/controllers for a simple table. > Index works fine, displaying all records in the table, and so does > edit. But when I click the 'view' link, I get this error: > > Notice (8): Undefined variable: title [APP/views/titles/view.ctp, line > 6] > > I have added the code (straight out of bake) below. I can't see > anything obviously wrong. Is this a known issue? Where is the error > likely to be? > > CODE: > > The model: > class Title extends AppModel { > > var $name = 'Title'; > var $validate = array( > 'title' => array('notempty'), > 'display_order' => array('numeric') > ); > > //The Associations below have been created with all possible keys, > those that are not needed can be removed > var $hasMany = array( > 'User' => array( > 'className' => 'User', > 'foreignKey' => 'title_id', > 'dependent' => false, > 'conditions' => '', > 'fields' => '', > 'order' => '', > 'limit' => '', > 'offset' => '', > 'exclusive' => '', > 'finderQuery' => '', > 'counterQuery' => '' > ) > ); > } > > The controller (truncated) > > class TitlesController extends AppController { > > var $name = 'Titles'; > var $helpers = array('Html', 'Form'); > > function index() { > $this->Title->recursive = 0; > $this->set('titles', $this->paginate()); > } > > function view($id = null) { > if (!$id) { > $this->flash(__('Invalid Title', true), > array('action'=>'index')); > } > $this->set('title', $this->Title->read(null, $id)); > } > > The view (truncated as it breaks on line 6 and subsequent rows): > <div class="titles view"> > <h2><?php __('Title');?></h2> > <dl><?php $i = 0; $class = ' class="altrow"';?> > <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); > ?></dt> > <dd<?php if ($i++ % 2 == 0) echo $class;?>> > <?php echo $title['Title']['id']; ?> > > > > -- Thanks & Regards, Vijayk. Co-founder (www.weboniselab.com) "You Bring the Dreams, We'll Bring the Means" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" 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 -~----------~----~----~----~------~----~------~--~---
