此配置适用于我的本地安装,但不适用于远程站点。
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的实例,没有给出
在本地工作似乎很奇怪,但不是来自远程站点。是不是因为某些原因找不到我服务的路径?
答案 0 :(得分:1)
<强>解决强>
哇,好吧,所以这发生了,因为当我最初安装zend-skeleton一段时间后,我已经禁用了开发模式,但现有配置的缓存文件已经在数据/缓存中创建。我在尝试思考本地和远程安装之间可能存在的不同时发现了这一点。修复是删除缓存文件。
对此解决方案有更好的解释和信誉: https://stackoverflow.com/a/45146213/5133172
文件恢复为只读,开发模式被禁用,所有文件都完美无缺。 :)