2008-2-19 22:51
zzdboy
帮我看看哪错了
Notice: Undefined variable: album in E:\www\vhosts\[url]www.zzd.com[/url]\application\controllers\IndexController.php on line 8
Fatal error: Call to a member function fetchAll() on a non-object in E:\www\vhosts\[url]www.zzd.com[/url]\application\controllers\IndexController.php on line 8
<?php
class IndexController extends Zend_Controller_Action
{
function init()
{
$this->view->baseUrl = $this->_request->getBaseUrl();
Zend_Loader::loadClass('Album');
$this->view->albums = $album->fetchAll();
}
function indexAction()
{
$this->view->title = "My Albums";
$album = new Album();
}
function addAction()
{
$this->view->title = "Add New Album";
}
function editAction()
{
$this->view->title = "Edit Album";
}
function deleteAction()
{
$this->view->title = "Delete Album";
}
}
2008-2-19 23:15
haohappy
[quote]原帖由 [i]zzdboy[/i] 于 2008-2-19 22:51 发表 [url=http://bbs.phpeye.com/redirect.php?goto=findpost&pid=1310&ptid=366][img]http://bbs.phpeye.com/images/common/back.gif[/img][/url]
Notice: Undefined variable: album in E:\www\vhosts\[url]www.zzd.com[/url]\application\controllers\IndexController.php on line 8
Fatal error: Call to a member function fetchAll() on a non-object in E:\www\vhosts ... [/quote]
错误很明显了,变量$album没有定义。你要在init()方法中添加这么一行:
$album = new Album();
为了让每个类方法都能使用这个$album变量,你可以这样定义:
[php]class IndexController {
private $album;
functioin init(){
Zend_Loader::loadClass('Album');
$this->album = new Album();
$this->view->albums = $this->album->fetchAll();
}
}[/php]