2015-12-07 5 views
5

मैं एक प्रणाली Zend फ्रेमवर्क 2 का उपयोग कर विकसित कर रहा हूँ में कारखाने द्वारा बंद की जगह और चाबी config_cache_enabledapplication.config.php में बंद एक त्रुटि प्राप्त कर दें:Zend फ्रेमवर्क 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 में बंद करने का उपयोग करने की अनुशंसा की गई क्योंकि यह कॉन्फ़िगरेशन कैश में इस त्रुटि के कारण हुआ था, इसके बारे में सोचकर मैंने कुछ पोस्ट पढ़ीं जो कारखाने द्वारा बंद करने की प्रतिलिपि बनाने की सिफारिश करती हैं।

यही मैंने किया है, मैंने एक कारखाना बनाया है और डीजी को टेबलगेटवे में 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); 
}, 

application.config.php - के बाद:

'factories' => array(
    'PedidosTable' => 'Admin\Service\PedidosTableFactory', 
), 
'aliases' => array(
    'Admin\Model\PedidosTable' => 'PedidosTable', 
), 

TableFactory:

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; 
    } 
} 
+1

यह एप्रोच सही है, हां। हालांकि, मैं आपको जादू विधि __invoke usung करने के लिए स्विच करने की सलाह देते हैं। मैं बाद में एक स्पष्टीकरण के साथ एक कोड नमूना पोस्ट करूंगा। – Stanimir

+0

हाँ यह ठीक है ... – tasmaniski

उत्तर

0

हाँ, इस तरह से कारखानों करना है। आप उदाहरण में उदाहरण के लिए उदाहरण में ZF3 MVC Zend\Authentication as a Service Factory और ज़ेंड "इन-गहराई" ट्यूटोरियल में उदाहरण देख सकते हैं: https://docs.zendframework.com/tutorials/in-depth-guide/models-and-servicemanager/#writing-a-factory-class। यहां तक ​​कि यदि यह ट्यूटोरियल ZF3 के लिए लिखा गया है, तो यह हिस्सा सबसे ज़्यादा ZF2 संस्करण के साथ पूरी तरह से संगत है।

संबंधित मुद्दे