A
A
Albert Tobacco2014-07-27 14:10:56
Zend Framework
Albert Tobacco, 2014-07-27 14:10:56

How to make zend framework 2.0 follow links?

here is my controller code

<?php
namespace Users\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController{
   public function indexAction(){
      $view = new ViewModel();
      return $view;

   }
   public function registerAction(){
      $view = new ViewModel();
      $view->setTemplate('users/index/new-user');
      return $view;

   }
   public function loginAction(){
      $view = new ViewModel();
      $view->setTemplate('users/index/login');   
      return $view;

   }
}

put the appropriate .phtml files in the view/users/index/ folder,
but when going to the page - 404.
What was done wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Albert Tobacco, 2014-07-27
@bighoc

The answer was found, you need to edit config/module.config.php
for walking on the links, the view should be like that.

<?php 
return array(
  'view_manager' => array(
    'template_path_stack' => array(
      __DIR__.'/../view'
      )
    ),
  
  'router'=> array(
    'routes'=>array(
      'users'=>array(
        'type' =>'Zend\Mvc\Router\Http\Literal',
        'options' => array(
          'route'=>'/users',
          'defaults'=> array(
            '__NAMESPACE__'=> 'Users\Controller',
            'controller'=>'Index',
            'action'=>'index',
          )
        ),
        'may_terminate' => true,
                'child_routes' => array(
                    // This route is a sane default when developing a module;
                    // as you solidify the routes for your module, however,
                    // you may want to remove it and replace it with more
                    // specific routes.
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
      )
    )
  ),
  'controllers'=>array(
    'invokables'=>array(
      'Users\Controller\Index'=> 'Users\Controller\IndexController'
      )
    ),
)
?>

G
Grag, 2014-07-27
@Grag

I had nothing to do with Zend, but maybe /user/index/login?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question