我創建了一個基於Zend的Album實例的Zend Framework 2管理網站。 一切在HomeController中工作,它充當我的默認控制器。但是,當我創建另一個控制器時,視圖將不會加載。這是我在indexAction中的代碼。Zend Framewrok 2返回ViewModel不工作
namespace Admin\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Helper\ViewModel;
use Admin\Model\Map\User;
class UserController extends AbstractActionController
{
protected $userTable;
public function indexAction()
{
$users = $this->getUserTable()->fetchAll();
$viewData = array(
'users' => $users
);
$vm = new ViewModel($viewData);
var_dump($vm);
return $vm;
}
public function getUserTable()
{
if(!$this->userTable)
{
$sm = $this->getServiceLocator();
$this->userTable = $sm->get('Admin\Model\Table\UserTable');
}
return $this->userTable;
}
}
我確定表格數據沒有問題,因爲它在我打印時顯示所有數據。但是,var_dump
結果總是這樣:
object(Zend\View\Helper\ViewModel)#280 (3) { ["current":protected]=> NULL ["root":protected]=> NULL ["view":protected]=> NULL }
但是,認爲將很好地加載,當我刪除行return $vm;
,這是沒用的,當然,因爲我不能傳遞任何數據查看,如果我不要返回ViewModel。
在它需要的情況下,這是我的看法經理module.config.php設置:
// View
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
// Admin page index
'admin/home/index' => __DIR__ . '/../view/admin/home/index.phtml',
'admin/user/index' => __DIR__ . '/../view/admin/user/index.phtml',
'admin/ticket/index' => __DIR__ . '/../view/admin/ticket/index.phtml',
'admin/transaction/index' => __DIR__ . '/../view/admin/transaction/index.phtml',
'admin/customer/index' => __DIR__ . '/../view/admin/customer/index.phtml',
'admin/payment/index' => __DIR__ . '/../view/admin/payment/index.phtml',
'admin/comment/index' => __DIR__ . '/../view/admin/comment/index.phtml',
'admin/appstat/index' => __DIR__ . '/../view/admin/appstat/index.phtml',
'admin/sysstat/index' => __DIR__ . '/../view/admin/sysstat/index.phtml',
'admin/account/index' => __DIR__ . '/../view/admin/account/index.phtml',
),
'template_path_stack' => array(
'home' => __DIR__ . '/../view',
'user' => __DIR__ . '/../view',
'ticket' => __DIR__ . '/../view',
'transaction' => __DIR__ . '/../view',
'customer' => __DIR__ . '/../view',
'payment' => __DIR__ . '/../view',
'comment' => __DIR__ . '/../view',
'appstat' => __DIR__ . '/../view',
'sysstat' => __DIR__ . '/../view',
'account' => __DIR__ . '/../view',
),
),
請告訴我哪裏是我的錯。謝謝。
最新的錯誤消息:) – Sam
我已經通過使用PHP ini啓用了錯誤消息。沒有單個錯誤消息出現。只是正確的看法phtml不會加載。 – yunhasnawa
error_reporting(E_ALL | E_STRICT); - 重試 - 檢查error_log;) – Sam