Php Zend Framewrok 2返回视图模型不工作

Php Zend Framewrok 2返回视图模型不工作,php,zend-framework2,Php,Zend Framework2,我根据Zend的专辑示例创建了一个Zend Framework 2管理网站。 一切都在HomeController中工作,它作为我的默认控制器。但是,当我创建另一个控制器时,视图将不会加载。这是我的索引代码 namespace Admin\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Helper\ViewModel; use Admin\Model\Map\User; class Us

我根据Zend的专辑示例创建了一个Zend Framework 2管理网站。 一切都在HomeController中工作,它作为我的默认控制器。但是,当我创建另一个控制器时,视图将不会加载。这是我的索引代码

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\u dump
的结果总是这样:

object(Zend\View\Helper\ViewModel)#280 (3) { ["current":protected]=> NULL ["root":protected]=> NULL ["view":protected]=> NULL }
但是,当我删除行
return$vm时,视图将被很好地加载,这当然是无用的,因为如果不返回ViewModel,我将无法将任何数据传递给view

如果需要,这是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',
        ),
    ),

请告诉我哪里错了。谢谢。

我想您已经使用了帮助器ViewModel(
Zend\View\helper\ViewModel
)来提供此功能

object(Zend\View\Helper\ViewModel)#280 (3) { ["current":protected]=> NULL ["root":protected]=> NULL ["view":protected]=> NULL }
请使用model ViewModel(
Zend\View\model\ViewModel
)而不是像下面这样的助手

use Zend\View\Model\ViewModel;

希望这对你有帮助

我认为您使用了helper-ViewModel(
Zend\View\helper\ViewModel
)来提供此功能

object(Zend\View\Helper\ViewModel)#280 (3) { ["current":protected]=> NULL ["root":protected]=> NULL ["view":protected]=> NULL }
请使用model ViewModel(
Zend\View\model\ViewModel
)而不是像下面这样的助手

use Zend\View\Model\ViewModel;

希望这对你有帮助

我认为您使用了helper-ViewModel(
Zend\View\helper\ViewModel
)来提供此功能

object(Zend\View\Helper\ViewModel)#280 (3) { ["current":protected]=> NULL ["root":protected]=> NULL ["view":protected]=> NULL }
请使用model ViewModel(
Zend\View\model\ViewModel
)而不是像下面这样的助手

use Zend\View\Model\ViewModel;

希望这对你有帮助

我认为您使用了helper-ViewModel(
Zend\View\helper\ViewModel
)来提供此功能

object(Zend\View\Helper\ViewModel)#280 (3) { ["current":protected]=> NULL ["root":protected]=> NULL ["view":protected]=> NULL }
请使用model ViewModel(
Zend\View\model\ViewModel
)而不是像下面这样的助手

use Zend\View\Model\ViewModel;

希望这对你有帮助

错误消息是什么:)我已经使用PHPINI启用了错误消息。没有出现单一错误消息。只有正确的视图phtml不会加载。错误报告(E|u ALL | E|u STRICT);-重试-检查错误(日志;)谢谢,但它不起作用。日志上没有显示错误。是的,显示了其他错误,但此ViewModel没有错误。错误消息是什么:)我已使用php ini启用了错误消息。没有出现单一错误消息。只有正确的视图phtml不会加载。错误报告(E|u ALL | E|u STRICT);-重试-检查错误(日志;)谢谢,但它不起作用。日志上没有显示错误。是的,显示了其他错误,但此ViewModel没有错误。错误消息是什么:)我已使用php ini启用了错误消息。没有出现单一错误消息。只有正确的视图phtml不会加载。错误报告(E|u ALL | E|u STRICT);-重试-检查错误(日志;)谢谢,但它不起作用。日志上没有显示错误。是的,显示了其他错误,但此ViewModel没有错误。错误消息是什么:)我已使用php ini启用了错误消息。没有出现单一错误消息。只有正确的视图phtml不会加载。错误报告(E|u ALL | E|u STRICT);-重试-检查错误(日志;)谢谢,但它不起作用。日志上没有显示错误。是,显示了其他错误,但此ViewModel没有错误。