And ... $this->set(compact('games')); Em quarta-feira, 29 de agosto de 2012 08h40min58s UTC-3, Lucas Simon Rodrigues Magalhaes escreveu: > > change this variable $game = $this->Game->find('all'); > to > $games = = $this->Game->find('all'); > > in IndexsController . > > > Em quarta-feira, 29 de agosto de 2012 05h08min00s UTC-3, Nareh Tarasyan > escreveu: >> >> Hi people. >> I'm a beginner in CakePHP. >> And I need help. >> >> I try to use loadModel. >> >> I have two models: games and words. >> >> In db have two tables: games(where I keep game difficulty levels) and >> words(where I keep words that I use in my game). >> >> Now I created IndexsController, where I load two models. >> Here is how I do it: >> >> <?php >> >> class IndexsController extends AppController { >> public $helpers = array('Html', 'Form', 'Session'); >> public $components = array('Session'); >> >> >> public function index() { >> $this->loadModel('Game'); >> $game = $this->Game->find('all'); >> $this->set('games', $this->Game->find('all')); >> >> >> $this->loadModel('Word'); >> $word = $this->Word->find('all'); >> $this->set('words', $this->Word->find('all')); >> } >> } >> ?> >> >> In View/Indexs I keep two files: index and view. >> Here are they: >> >> index.ctp >> >> <body> >> >> <table> >> <tr> >> <th>Difficulty</th> >> </tr> >> >> <!-- Here's where we loop through our $games array, printing out post >> info --> >> >> <?php foreach ($games as $game): ?> >> <tr> >> <td> >> <?php echo $this->Html->link($game['Game']['difficulty'], array('action' >> => 'view', $game['Game']['id'])); ?> >> </td> >> >> </tr> >> <?php endforeach; ?> >> >> </table> >> </body> >> >> >> and view.ctp: >> <body> >> <h1><?php echo "Number of experiments left to try:" >> .($game['Game']['difficulty']); ?></h1> >> </body> >> >> >> Index.ctp works perfect, but in view.ctp it says: >> >> Undefined variable: game [APP\View\Indexs\view.ctp, line 9] >> >> What should I do??? >> >> THanks everybody [image: smile.gif] >> >
-- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.