Skip to content

Instantly share code, notes, and snippets.

@JiNexus
Last active July 24, 2016 18:33
Show Gist options
  • Save JiNexus/24f47bb4d06f851801195baba6dbf843 to your computer and use it in GitHub Desktop.
Save JiNexus/24f47bb4d06f851801195baba6dbf843 to your computer and use it in GitHub Desktop.
Unable to resolve service "Zend\ServiceManager\ServiceLocatorInterface" to a factory; are you certain you provided it during configuration?
<?php
/**
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
use Application\Factory\TestFactory;
return [
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'test' => [
'type' => Literal::class,
'options' => [
'route' => '/test',
'defaults' => [
'controller' => Controller\TestController::class,
'action' => 'index',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:action]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
'controllers' => [
'invokables' => array(
// 'Application\Controller\Test' => Controller\TestController::class,
),
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
Controller\TestController::class => TestFactory::class,
],
],
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'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' => [
__DIR__ . '/../view',
],
],
'navigation' => [
'default' => [
[
'label' => 'Home',
'route' => 'home',
],
[
'label' => 'Test',
'route' => 'test',
],
[
'label' => 'Album',
'route' => 'album',
'pages' => [
[
'label' => 'Add',
'route' => 'album',
'action' => 'add',
],
[
'label' => 'Edit',
'route' => 'album',
'action' => 'edit',
],
[
'label' => 'Delete',
'route' => 'album',
'action' => 'delete',
],
],
],
],
],
];
<?php
/**
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
// use Zend\Mvc\ModuleRouteListener;
// use Zend\Mvc\MvcEvent;
class Module
{
const VERSION = '3.0.0dev';
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
}
<?php
/**
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\ServiceManager\ServiceLocatorInterface;
class TestController extends AbstractActionController
{
private $serviceLocator;
public function __construct(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}
public function indexAction()
{
echo '<pre>';
var_dump('index');
echo '</pre>';
return new ViewModel();
}
}
<?php
namespace Application\Factory;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
use Application\Controller\TestController;
class TestFactory
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new TestController($container->get(ServiceLocatorInterface::class));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment