我已經從CakePHP 1.3遷移到CakePHP 2.x,但在新聞列表中,我收到此錯誤消息:「通知(8):未定義變量」在View中(從CakePHP 1.x遷移到2.x)
Notice (8): Undefined variable: newsSet [APP/View/newsSets/view.ctp, line 19]
我的控制器:
class NewsSetsController extends AppController {
public $name = 'newsSets';
public $helpers = array('Html', 'Form', 'Session');
public $uses = array('Client', 'Block', 'NewsSet', 'Curse', 'Gallery', "News");
public function index() {
$this->NewsSet->recursive = 0;
$this->set('newsSets', $this->paginate());
}
public function view($id = null) {
if (!$id) {
$this->flash(__('Invalid NewsSet', true), array('action'=>'index'));
}
$newsset = $this->NewsSet->read(null, $id);
$block = $this->NewsSet->Curse->Block->findById($newsset['Curse']['block_id']);
$this->set('block', $block);
$news = $this->NewsSet->News->find("all", array('conditions' => array('News.news_set_id' => $id), 'order' => 'News.order ASC, News.created DESC' , 'recursive' => 1));
$this->set('news', $news);
$tree = $this->navTree($id, $newsset['NewsSet']['curse_id']);
$this->set('tree', $tree);
}
}
我的觀點:
<p><i>Creat: <?php echo $newsSet['NewsSet']['created']; ?></i></p>
嗨@InigoFlores,謝謝。 我已經做了更改,但它不起作用: 未定義的索引:NewsSet – r22s
我認爲這是第二行失敗。請確認'News belongsTo NewsSet'。 –