Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Framewrok 2 return ViewModel not working
    primarykey
    data
    text
    <p>I created a Zend Framework 2 admin website based on Zend's Album example. Everything works in HomeController which is acted as my default controller. However when I created another controller, the view won't loaded. This is my code in indexAction.</p> <pre><code>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-&gt;getUserTable()-&gt;fetchAll(); $viewData = array( 'users' =&gt; $users ); $vm = new ViewModel($viewData); var_dump($vm); return $vm; } public function getUserTable() { if(!$this-&gt;userTable) { $sm = $this-&gt;getServiceLocator(); $this-&gt;userTable = $sm-&gt;get('Admin\Model\Table\UserTable'); } return $this-&gt;userTable; } } </code></pre> <p>I'm sure that there is nothing wrong with the table data because it showed up all data when I printed it. However, the result of <code>var_dump</code> are always like this:</p> <pre><code>object(Zend\View\Helper\ViewModel)#280 (3) { ["current":protected]=&gt; NULL ["root":protected]=&gt; NULL ["view":protected]=&gt; NULL } </code></pre> <p>But, the view will loaded nicely when I remove the line <code>return $vm;</code>, this is useless of course, because I can't pass any data to view if I don't return the ViewModel.</p> <p>In case it needed, this is my view manager setting in module.config.php:</p> <pre><code>// View 'view_manager' =&gt; array( 'display_not_found_reason' =&gt; true, 'display_exceptions' =&gt; true, 'doctype' =&gt; 'HTML5', 'not_found_template' =&gt; 'error/404', 'exception_template' =&gt; 'error/index', 'template_map' =&gt; array( 'layout/layout' =&gt; __DIR__ . '/../view/layout/layout.phtml', 'error/404' =&gt; __DIR__ . '/../view/error/404.phtml', 'error/index' =&gt; __DIR__ . '/../view/error/index.phtml', // Admin page index 'admin/home/index' =&gt; __DIR__ . '/../view/admin/home/index.phtml', 'admin/user/index' =&gt; __DIR__ . '/../view/admin/user/index.phtml', 'admin/ticket/index' =&gt; __DIR__ . '/../view/admin/ticket/index.phtml', 'admin/transaction/index' =&gt; __DIR__ . '/../view/admin/transaction/index.phtml', 'admin/customer/index' =&gt; __DIR__ . '/../view/admin/customer/index.phtml', 'admin/payment/index' =&gt; __DIR__ . '/../view/admin/payment/index.phtml', 'admin/comment/index' =&gt; __DIR__ . '/../view/admin/comment/index.phtml', 'admin/appstat/index' =&gt; __DIR__ . '/../view/admin/appstat/index.phtml', 'admin/sysstat/index' =&gt; __DIR__ . '/../view/admin/sysstat/index.phtml', 'admin/account/index' =&gt; __DIR__ . '/../view/admin/account/index.phtml', ), 'template_path_stack' =&gt; array( 'home' =&gt; __DIR__ . '/../view', 'user' =&gt; __DIR__ . '/../view', 'ticket' =&gt; __DIR__ . '/../view', 'transaction' =&gt; __DIR__ . '/../view', 'customer' =&gt; __DIR__ . '/../view', 'payment' =&gt; __DIR__ . '/../view', 'comment' =&gt; __DIR__ . '/../view', 'appstat' =&gt; __DIR__ . '/../view', 'sysstat' =&gt; __DIR__ . '/../view', 'account' =&gt; __DIR__ . '/../view', ), ), </code></pre> <p>Please show me where is my mistake. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload