I am trying to create HelloWorld Module using Zend Framework but its not working.I only gets this error:
Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "helloworldcontrollerindex(alias: HelloWorld\Controller\Index)" via invokable class "HelloWorld\Controller\IndexController"; class does not exist
Please Help me find why its being not working.
This Directory structure :
HelloWorld
->Module.php
->config
->Module.config.php
->src
->HelloWorld
->Controller
->view
->helloworld
->Controller
->index.phtml
Module.php
<?php
namespace HelloWorld;
use HelloWorld\Controller;
use Zend\Mvc\ModuleRouteListner;
use Zend\Mvc\MvcEvent;
class Module
{
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__,
),
),
);
}
}
?>
module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'HelloWorld\Controller\Index'
=> 'HelloWorld\Controller\IndexController',
),
),
'router' => array(
'routes' => array(
'write-hello-world' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/writehello',
'defaults' => array(
'controller' => 'HelloWorld\Controller\Index',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(__DIR__ . '/../view',),
),
);
?>
IndexController.php
<?php
namespace HelloWorld\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstarctActionController{
public function indexAction ()
{
$views = new ViewModel(array('test' => 'hello bhavik'));
$views->setTemplate('HelloWorld/index/index');
return $views;
}
}
?>
index.phtml
<h1>
<?php
echo $this->text;
?>
</h1>
use HelloWorld\Controller
in the begining ofModule.php
? – franssuuse Zend/View\Model\ViewModel;
in the controller. This might be causing a parse error. If that's not it - what's the full path to the location of IndexController.php? – Tim Fountain