に私はZend Frameworkの2を使用してシステムを開発し、キーconfig_cache_enabled
application.config.php
でクロージャを回していますが、エラーを受信:Zend Frameworkの2 - 工場で閉鎖を交換Module.php
Fatal error: Call to undefined method set_state Closure::__()in /home/user/www/myProject.com/data/cache/module-config-cache.app_config.php online 185.
より良い検索私はそれがありませんでしたModule.php
でクロージャを使用することを推奨しました。これは、これがコンフィギュレーションキャッシュでこのエラーの原因となったためです。私はクロージャを工場で置き換えることを推奨する記事を読んでいます。
私は工場を作り、TableGatewayのDIをModule.php
に置き換えて工場で完璧に働いていました。私のやり方はOKかどうかわかりません。
これが問題を解決する正しい方法だと誰にでも教えてください。
application.config.php
- 前: - はい、これは工場を行う方法である
namespace Admin\Service;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Admin\Model\Pedidos;
use Admin\Model\PedidosTable;
class PedidosTableFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$dbAdapter = $serviceLocator->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Pedidos());
$tableGateway = new TableGateway('pedidos', $dbAdapter, null, $resultSetPrototype);
$table = new PedidosTable($tableGateway);
return $table;
}
}
これは正しく、はいです。しかし、__invokeという魔法の方法に切り替えることをお勧めします。私は後で説明をつけてコードサンプルを投稿します。 – Stanimir
はい、問題ありません... – tasmaniski