传递给Application \ Controller \ IndexController :: __ construct()的Zend 3参数1必须是的实例,没有给出, [英] Zend 3 Argument 1 passed to Application\Controller\IndexController::__construct() must be an instance of , none given,

查看:68
本文介绍了传递给Application \ Controller \ IndexController :: __ construct()的Zend 3参数1必须是的实例,没有给出,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此配置适用于我的本地安装,但不适用于远程站点.

This configuration works on my local install, but not on remote site.

ExampleManager.php

<?php
namespace Application\Service;

use Application\Entity\SomeTable;

class ExampleManager 
{

    /**
     * Entity manager.
     * @var Doctrine\ORM\EntityManager
     */
    private $entityManager;

    public function __construct($entityManager) 
    {
      $this->entityManager = $entityManager;
    }

ExampleManagerFactory.php

<?php

namespace Application\Service\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use Application\Service\ExampleManager;

class ExampleManagerFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, 
    $requestedName, array $options = null)
    {
        $entityManager = $container->get('doctrine.entitymanager.orm_default');

        // instantiate the service and inject dependencies
        return new ExampleManager($entityManager);
    }
}

IndexControllerFactory.php

<?php

namespace Application\Controller\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use Application\Controller\IndexController;

class IndexControllerFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $exampleManager = $container->get(\Application\Service\ExampleManager::class);

        // instantiate the controller and inject dependencies
        return new IndexController($exampleManager);
    }
}

IndexController.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 Application\Service\ExampleManager;

class IndexController extends AbstractActionController
{
    /**
     * Example manager.
     * @var Application\Service\ExampleManager
     */
    private $exampleManager;

    public function __construct(ExampleManager $exampleManager) 
    {
      $this->exampleManager = $exampleManager;
    }

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;

use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Application\Service\ExampleManager;

return [
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],
    'controllers' => [
        'factories' => [
            Controller\IndexController::class => Controller\Factory\IndexControllerFactory::class,
        ],
    ],
    'service_manager' => [
        'factories' => [
            ExampleManager::class => Service\Factory\ExampleManagerFactory::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',
        ],
    ],
    'doctrine' => [
        'driver' => [
            __NAMESPACE__ . '_driver' => [
                'class' => AnnotationDriver::class,
                'cache' => 'array',
                'paths' => [__DIR__ . '/../src/Entity']
            ],
            'orm_default' => [
                'drivers' => [
                    __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
                ],
            ],
        ],
    ],
];

传递给Application \ Controller \ IndexController :: __ construct()的参数1必须是Application \ Service \ ExampleManager的实例,没有给出

Argument 1 passed to Application\Controller\IndexController::__construct() must be an instance of Application\Service\ExampleManager, none given

在本地工作而不是在远程站点工作似乎很奇怪.是否由于某种原因找不到我的服务之路?

Seems strange for it to work locally, but not from a remote site. Is it not finding the path to my service for some reason?

推荐答案

已解决

哇,好吧,发生这种情况的原因是,当我不久前最初安装zend-skeleton时,我已经禁用了开发模式,但是现有配置的缓存文件已在数据/缓存中创建.我在尝试考虑本地安装和远程安装之间可能有何不同时发现了这一点.解决方法是删除缓存文件.

Wow, ok so this happened because when I had initially installed zend-skeleton awhile back I had disabled development mode, but cache files of the existing config had been created in data/cache. I discovered this while trying to think what could be different between my local and remote install. The fix is to remove the cache files.

此处提供了对该解决方案的更好解释和认可: https://stackoverflow.com/a/45146213/5133172

A better explanation and credit for the solution is here: https://stackoverflow.com/a/45146213/5133172

文件又回到只读状态,禁用了dev模式,并且一切运行正常. :)

Files are back to read only, dev mode is disabled and all works perfectly. :)

这篇关于传递给Application \ Controller \ IndexController :: __ construct()的Zend 3参数1必须是的实例,没有给出,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆