I'm having an odd problem. If I have 1 module my routes are correctly matched and the pages returned. Add another module to the application config and BANG - it stops working and ends up in the Module.php of my second module (which has boostrapping and triggers loads of events).
application.config.php
<?php
return array(
'modules' => array(
'CMS',
'AOCS',
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
CMS module config
<?php
return array(
'router' => array(
'routes' => array(
'Admin' => array(
'type' => 'Literal',
'options' => array(
'route' => '/admin',
'defaults' => array(
'__NAMESPACE__' => 'CMS\Controller',
'controller' => 'Index',
'action' => 'Login',
),
),
'may_terminate' => true,
),
'Logout' => array(
'type' => 'Literal',
'options' => array(
'route' => '/logout',
'defaults' => array(
'__NAMESPACE__' => 'CMS\Controller',
'controller' => 'Index',
'action' => 'Logout',
),
),
),
'CMS/Welcome' => array(
'type' => 'Literal',
'options' => array(
'route' => '/aocs/welcome',
'defaults' => array(
'__NAMESPACE__' => 'AOCS\Controller',
'controller' => 'Welcome',
'action' => 'Welcome',
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'CMS\Controller\Index' => 'CMS\Controller\IndexController',
),
),
'translator' => array(
'locale' => 'en_GB',
),
'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__ . '/../templates/admin.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
AOCS module config
<?php
return array(
'router' => array(
'routes' => array(
'Welcome' => array(
'type' => 'Literal',
'options' => array(
'route' => '/welcome',
'defaults' => array(
'__NAMESPACE__' => 'AOCS\Controller',
'controller' => 'Welcome',
'action' => 'Welcome',
),
),
),
'Mains' => array(
'type' => 'segment',
'options' => array(
'route' => '/aocs[/:controller][/:action][/:id]',
'defaults' => array(
'__NAMESPACE__' => 'AOCS\Controller',
'controller' => 'Welcome',
'action' => 'Welcome',
),
),
'may_terminate' => true,
'child_routes' => array(
'query' => array(
'type' => 'Query',
),
),
),
),
),
'navigation' => array(
'menu' => array(
'page-1' => array(
'label' => 'Logout',
'route' => 'Logout',
'resource' => 'aocs_index_logout'
),
'page-2' => array(
'label' => 'Login',
'route' => 'Admin' ,
'resource' => 'cms_index_login'
),
),
),
'service_manager' => array(
'factories' => array(
'menu' => 'AOCS\Navigation\MenuNavigationFactory'
),
),
'controllers' => array(
'invokables' => array(
'AOCS\Controller\Welcome' => 'AOCS\Controller\WelcomeController'
),
),
'translator' => array(
'locale' => 'en_GB',
),
'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__ . '/../templates/admin.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
/*'strategies' => array(
'ViewJsonStrategy',
),*/
),
);
Module.php from CMS
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* #link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* #copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* #license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace CMS;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\View\Renderer\JsonRenderer;
use Zend\Di\Di;
use Zend\Config\Reader\Ini;
use Zend\Navigation\Navigation;
// AH core code
use Core\Classes\setDB;
use Core\Classes\setCache;
use Core\Models\SecurityModel;
use Core\Models\AclModel;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$sm = $e->getApplication()->getServiceManager();
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// Set config - required throughout
$reader = new Ini;
$sm->setService('configIni',$reader->fromFile('./config/application.ini'));
// Setup a Database connection
$sm->setService('setDB',new setDB($sm,'database'));
// Setup Caching
$sm->setService('setCache',new setCache($sm));
/*$eventManager->attach('dispatch', function ($sm) use ($controllers) {
print'<pre>[CMS]';print_r($sm->getRouteMatch());print'</pre>';
exit;
}, 100); // execute before executing action logic*/
// Assign system names to view models so we can set across templates
$view = $e->getViewModel();
$config = $sm->get('configIni');
$view->setVariable('systemname',$config['system']['name']);
$view->setVariable('systemshort',$config['system']['shortname']);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
Am I missing something obvious? Its really annoying!
Thanks
Antony
Fixed it!
The BANG was that I have a dispatch in the 2x Modules.php which for some reason were triggering automatically. As the 2nd checked if the user is logged in and they weren't it redirected causing problems.
The issue wasn't to do with my config it appears (unless I'm missing the obvious) that this is a bug in ZF2 where the dispatch events are not tied to the module they're called from but all get run automatically.
So if my page is in CMS module the AOCS modules > bootstrap is still run. Why??
Thanks for the point about type = Query - will update.
Related
I've got a big problem because I can see index.html give it by IndexController, but if I create another action, for example, getdataAction() I have the next error:
I think that I have not to configure anything to do that, but these are my files:
module_config.php
namespace Application;
return array(
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Application/Entity')
),
'orm_default' => array(
'drivers' => array(
'Application\Entity' => 'application_entities'
)
)
)
),
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index'
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/Application',
'defaults' => array(
__NAMESPACE__ => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'factories' => array(
'translator' => 'Zend\Mvc\Service\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => Controller\IndexController::class
//'Application\Controller\Index' => 'Application\Controller\IndexController'
),
),
'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',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
IndexController.php
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Entity\UserEntity;
class IndexController extends AbstractActionController
{
protected $_objectManager;
public function indexAction(){
try{
$users = $this->getObjectManager()->getRepository('\Application\Entity\UserEntity')->findAll();
foreach ($users as $user){
echo "[id]: " . $user->getId() . " Nombre: " . $user->getFullName() . "<br />";
}
}catch(Exception $ex){
echo "error: " . $ex->getMessage();
}
return new ViewModel(array("users" => $users));
}
public function getdataAction(){
return new ViewModel();
}
protected function getObjectManager()
{
if (!$this->_objectManager) {
$this->_objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
}
return $this->_objectManager;
}
}
The directory structure is the next:
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/Application',
'defaults' => array(
__NAMESPACE__ => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
This code is wrong you have to quote this NAMESPACE key
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/Application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
It will be fix this issue
Index(resolves to invalid controller class or alias: Index)
In the other hand you use this :
'invokables' => array(
'Application\Controller\Index' => Controller\IndexController::class
You almost have this right, but you have to put the complete Full Qualified Class Name (FQCN)
'invokables' => array(
'Application\Controller\Index' => Application\Controller\IndexController::class
EDIT :
You define your main route as /Application and
'defaults' => array(
__NAMESPACE__ => 'Application\Controller',
'controller' => 'Index',
ucfirst matters here try it.
http://localhost/Application/Index/getdata
and
http://localhost/application/index/getdata
You don't have any route to your action.
The skeleton application defines a catch all route as standard, which you call via:
/application/:controller/:action
So you should be able to use:
/application/index/getdata
To get a better route you'll need to define one in module_config.
Finally, I succeeded installing zf2 , now I'm trying to accessing a function but i get the 404 page .
This is my code :
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController{
public function indexAction(){
return new ViewModel();
}
public function addAction(){
echo 1;
}
public function editAction(){
}
public function deleteAction(){
}
}
when i access mylink/add it redirects me to 404. Why ?
This is the route:
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController'
),
),
'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',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
Can someone explain me where i have to modify the route to access the function addAction??? or to access a new controller ? for example : myproject/mynewcontroller or myproject/add ? thx
You need to configure a route to call that function, something along the lines of:
'router' => array(
'routes' => array(
'index' => array(
'type' => 'Literal',
'options' => array(
'route' => '/add',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'add',
),
),
I'm not entirely sure if this code is valid, since I haven't used routing in zend in a while, but it should be something in that direction. Refer to the zend framework docs for more ino: http://framework.zend.com/manual/current/en/modules/zend.mvc.routing.html
It might be possible you forget to add controller invokables in your module.config.php file try this:
<?php
return array(
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController',
),
),
...
...
);
Site links:
http://test.scampaigns.com/Frontend/index
https://test.scampaigns.com/Frontend/index
Problem:
Number 1 is working, number 2 is giving 404 error.
The problem is with HTTP the site is working fine. but with HTTPS only the default controller is working but other controllers are not working with the https:
Below is my module.config.php
<?php
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/', //edited by koushik
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '[:controller[/:action]][/:id][/:pId][/:devId]', //edited by koushik
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController',
'Application\Controller\Developer' => 'Application\Controller\DeveloperController', // edited by Poulami
'Application\Controller\Template' => 'Application\Controller\TemplateController', // edited by Poulami
'Application\Controller\Admin' => 'Application\Controller\AdminController',
'Application\Controller\Frontend' => 'Application\Controller\FrontendController',
'Application\Controller\Ajaxcall' => 'Application\Controller\AjaxcallController'
),
),
'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',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),// Added by Baishakhi
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
Is there any one who can help me and give me solution?
zend doesn't matter what url scheme is used when trying to find a RouteMatch with your router configuration.
i think your problem is located in your apache configuration that your https vhost don't allow .htaccess files in your public folder.
when all urls fail and the index.php is working - this indicates a rewrite problem. check your apache configuration and that your public folder can override htaccess files with the option
AllowOverride All
If you want to use https in your route you need to use the Zend\Mvc\Router\Http\Scheme router. All you need is to add an option in your route configuration: 'scheme' => 'https'.
You can follow this simple example :
'router' => array(
'routes' => array(
'name_route' => array(
'type' => 'Scheme', //<-----add the type Schema here.
'options' => array(
'route' => '/url',
'scheme' => 'https', //<-----specify this here.
'defaults' => array(
//set the default options here.
),
),
),
// ....
),
),
You can also see this post.
When I Click - my index page -
localhost/gov_app/public/approval_allowances/institute/index
It displays the Data Set with Pagination.If i click "<<" or ">>" then it goes to localhost/gov_app/public/approval_allowances/?page=2
Unfortuantely ZF2 Pagination Control Gives Wrong Links.Here is my Codes
index.phtml
<?php echo $this->paginationControl($this->paginator, 'Elastic', 'approval_allowances/institute/partial/paginator.phtml') ?>
<?php
// add at the end of the file after the table
echo $this->paginationControl(
// the paginator object
$paginator,
// the scrolling style
'sliding',
// the partial to use to render the control
array('approval_allowances/institute/partial/paginator.phtml','Approval_allowances'),
// the route to link to when a user clicks a control link
array('route' => 'institute')
);
?>
module.config.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* #link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* #copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* #license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Approval_allowances\Controller\Index',
'action' => 'index',
),
),
),
'institute' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/approval_allowances/institute',
'defaults' => array(
'controller' => 'Approval_allowances\Controller\Institute',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'allowance_approval' => array(
'type' => 'Literal',
'options' => array(
'route' => '/approval_allowances',
'defaults' => array(
'__NAMESPACE__' => 'Approval_allowances\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Approval_allowances\Controller\Index' => 'Approval_allowances\Controller\IndexController',
'Approval_allowances\Controller\Institute' => 'Approval_allowances\Controller\InstituteController'
),
),
'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',
'approval_allowances/index/index' => __DIR__ . '/../view/approval_allowances/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
Change your index.phtml file to include the index action along with the route. Like this:
<?php echo $this->paginationControl($this->paginator, 'Elastic', 'approval_allowances/institute/partial/paginator.phtml') ?>
<?php
// add at the end of the file after the table
echo $this->paginationControl(
// the paginator object
$paginator,
// the scrolling style
'sliding',
// the partial to use to render the control
array('approval_allowances/institute/partial/paginator.phtml','Approval_allowances'),
// the route to link to when a user clicks a control link
array('route' => 'institute'
'options' => array(
'action' => 'index'
)
)
);
Anyone know how to change the default Module in Zend Framework 2? I am using the Skeleton Application as the home page but I want to make another module that I have the default home page.
I tried two things
I removed the "Skeleton Application" from the application.config.php file this is what it looked like
return array(
'modules' => array(
'Application',
'Helloworld'
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
this is what it looks like now
return array(
'modules' => array(
'Helloworld'
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
if you can't tell I removed the 'Application' from the module
then I changed my module.config.php file for the Helloworld module
here's what it used to look like
return array(
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
'router' => array(
'routes' => array(
'sayhello' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/sayhello',
'defaults' => array(
'controller' => 'Helloworld\Controller\Index',
'action' => 'index',
)
)
)
)
),
'controllers' => array(
'factories' => array(
'Helloworld\Controller\Index' => 'Helloworld\Controller\IndexControllerFactory'
)
),
'service_manager' => array(
'invokables' => array(
'greetingService' => 'Helloworld\Service\GreetingService'
)
)
);
this is what it looks like now
return array(
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
'router' => array(
'routes' => array(
'sayhello' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Helloworld\Controller\Index',
'action' => 'index',
)
)
)
)
),
'controllers' => array(
'factories' => array(
'Helloworld\Controller\Index' => 'Helloworld\Controller\IndexControllerFactory'
)
),
'service_manager' => array(
'invokables' => array(
'greetingService' => 'Helloworld\Service\GreetingService'
)
)
);
the change was made to the 'router' array in the options=>route I changed the value to just '/'
but it throws a 5000 error
can anyone elaborate on what I am doing wrong?
OK so I saw the problem with my application. The routing is actually correct the problem was that I was missing a layout.phtml file I needed to specify all this in the module configuration. I need to add the following to my module.config.php
'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',
'valaree/index/index' => __DIR__ . '/../view/valaree/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
)
you can set your project home page by setting url in module.config.php of application module
(myproject/module/application/config/module.config.php) in home route. For Example, if you want to use Index Action of Index Controller of Default Module as your home page you need to change the home route in above mentioned file. i.e
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Default\Controller\Index',
'action' => 'index',
),
),
),
Please make sure you define your new module in (myproject/config/application.config.php) before using above code. Please let me know if you required any further help. Thanks..:)