我正在使用Zend Framework 2开发一个系统,并config_cache_enabled在application.config.php关闭时关闭密钥收到错误:
致命错误:在/home/user/www/myProject.com/data/cache/module-config-cache.app_config.php在线调用未定义的方法set_state Closure :: __()185.
搜索得更好我发现不建议使用闭包,Module.php因为这是导致配置缓存中出现此错误的原因,考虑到这一点我读了一些建议用工厂替换闭包的帖子.
这就是我做的,我创建了一个工厂,并在工厂取代了TableGateway中的DI Module.php并且工作得很好,我的问题是我不知道我的方式是否正常.
谁能告诉我这是否是解决问题的正确方法?
application.config.php - 之前:
'Admin\Model\PedidosTable' => function($sm) {
$tableGateway = $sm->get('PedidosTableGateway');
$table = new PedidosTable($tableGateway);
return $table;
},
'PedidosTableGateway' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Pedidos());
return new TableGateway('pedidos', $dbAdapter, null, $resultSetPrototype);
},
Run Code Online (Sandbox Code Playgroud)
application.config.php - 之后:
'factories' => array(
'PedidosTable' => 'Admin\Service\PedidosTableFactory',
),
'aliases' => array(
'Admin\Model\PedidosTable' => 'PedidosTable',
),
Run Code Online (Sandbox Code Playgroud)
TableFactory:
namespace Admin\Service;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use …Run Code Online (Sandbox Code Playgroud)