Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Pages: 1
Je parviens à charger toutes mes classes de type View Helpers par:
module.config.php du module Application
'Zend\View\HelperLoader' => array( 'parameters' => array( 'map' => array( 'simpleurl' => 'Mix\View\Helper\SimpleUrl', 'translator' => 'Mix\View\Helper\Translator', 'config' => 'Mix\View\Helper\Config', 'cdn' => 'Mix\View\Helper\Cdn', ), ), ),
Les action helpers n'existant plus, je suppose que je dois les remplacer par des plugins.
Or la classe Zend\Mvc\Controller\PluginLoader ayant les mêmes caractéristiques que Zend\View\HelperLoader j'ai donc ajouté la directive suivante en espérant charger mon plugin 'config':
'Zend\Mvc\Controller\PluginLoader' => array( 'parameters' => array( 'map' => array( 'config' => 'Mix\Mvc\Controller\Plugin\Config', ), ), ),
J'apelle ensuite le plugin de cette facon:
namespace Application\Controller; use Mix\Mvc\Controller\Action; class IndexController extends Action { public function indexAction() { $result = $this->plugin('config',array('param1','param2')); } }
Mais cela ne fonctionne pas:
Message: Unable to locate class associated with "config"
#0 F:\ZEND\APPLICATIONS\exotica\zf2\library\Zend\Mvc\Controller\PluginBroker.php(54): Zend\Loader\PluginBroker->load('config', Array)
#1 F:\ZEND\APPLICATIONS\exotica\zf2\library\Zend\Mvc\Controller\ActionController.php(273): Zend\Mvc\Controller\PluginBroker->load('config', Array)
#2 F:\ZEND\\application\modules\Application\src\Application\Controller\IndexController.php(9): Zend\Mvc\Controller\ActionController->plugin('config', Array)
Toute aide est bien sûr la bienvenue...
David
Dernière modification par booradley (13-11-2011 20:30:15)
Hors ligne
Est-ce que ça marche mieux si tu ajoute ça dans module.config.php ?
'Zend\Mvc\Controller\PluginBroker' => array( 'parameters' => array( 'loader' => 'Zend\Mvc\Controller\PluginLoader' ) ),
Hors ligne
Effectivement j'avais oublié ce bout de code pour que ca fonctionne comme les view helpers.
Mais non ca ne fonctionne pas non plus.
Meme avec
$result = $this->getBroker()->load('config',array('param1','param2'));
au lieu de
$result = $this->plugin('config',array('param1','param2'));
Je continue à chercher..
Hors ligne
Il faudrait plutôt tout le code qui permet de configure le Di pour le module. Je pense que le problème se situe plutôt du côté comment tu changes le broker par défaut d'un contrôleur ? Il faut avoir à l'esprit qu'on utilise généralement un seul moteur de vue, mais plusieurs contrôleurs. Il faut au moins attacher ce broker personnalisé au contrôleur "application-index". Tu peux essayer avec un code approximatif suivant :
[lang=php] class IndexController extends ActionController { public function indexAction() { $this->setBroker($this->getLocator()->get('Zend\Mvc\Controller\PluginBroker')); $result = $this->plugin('config',array('param1','param2')); } }
Le plus simple étant surement d'utiliser le fait qu'une méthode setter est remplie automatiquement par le Di.
[lang=php] // Voir ActionController::setBroker($broker) et l'instance de Zend\Mvc\Controller\PluginBroker configurée par le Di use Zend\Mvc\Controller\PluginBroker as Broker; class IndexController extends ActionController { public function indexAction() { $result = $this->plugin('config',array('param1','param2')); } }
Dernière modification par Intiilapa (15-11-2011 20:06:22)
Hors ligne
Je vois pas trop comment.
Voici le code de ma config:
'instance' => array( 'alias' => array( 'error' => 'Application\Controller\ErrorController', 'index' => 'Application\Controller\IndexController', 'view' => 'Zend\View\PhpRenderer', 'view-resolver' => 'Zend\View\TemplatePathStack', 'view-broker' => 'Zend\View\HelperBroker', 'view-loader' => 'Zend\View\HelperLoader', 'plugin-broker' => 'Zend\Mvc\Controller\PluginBroker', 'plugin-loader' => 'Zend\Mvc\Controller\PluginLoader', ), 'plugin-broker' => array('parameters' => array( 'loader' => 'plugin-loader', )), 'plugin-loader' => array('parameters' => array( 'map' => array( 'config' => 'Mix\Mvc\Controller\Plugin\Config', ), )), ... ),
Dernière modification par booradley (16-11-2011 21:54:12)
Hors ligne
Effectivement je suis obligé de faire
$result = $this->plugin('Mix\Mvc\Controller\Plugin\Config',array('param1','param2'));
pour que ca fonctionne fonctionne
Ca m'arrange pas vraiment .....
Dernière modification par booradley (17-11-2011 14:18:41)
Hors ligne
De même les plugins Zend ne sont pas trouvés:
Dans mon controlleur,
$this->plugin('json');
retourne Message: Unable to locate class associated with "json"
Hors ligne
Et j'utilise le dernier fichier Module.php du skeleton:
<?php namespace Application; use Zend\Module\Manager, Zend\EventManager\StaticEventManager, Zend\Module\Consumer\AutoloaderProvider; class Module implements AutoloaderProvider { protected $view; protected $viewListener; public function init(Manager $moduleManager) { $events = StaticEventManager::getInstance(); $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100); } public function getAutoloaderConfig() { return array( 'Zend\Loader\ClassMapAutoloader' => array( __DIR__ . '/autoload_classmap.php', ), 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } public function getConfig($env = null) { return include __DIR__ . '/configs/module.config.php'; } public function initializeView($e) { $app = $e->getParam('application'); $locator = $app->getLocator(); $config = $e->getParam('config'); $view = $this->getView($app); $viewListener = $this->getViewListener($view, $config); $app->events()->attachAggregate($viewListener); $events = StaticEventManager::getInstance(); $viewListener->registerStaticListeners($events, $locator); } protected function getViewListener($view, $config) { if ($this->viewListener instanceof View\Listener) { return $this->viewListener; } $viewListener = new View\Listener($view, $config->layout); $viewListener->setDisplayExceptionsFlag($config->display_exceptions); $this->viewListener = $viewListener; return $viewListener; } protected function getView($app) { if ($this->view) { return $this->view; } $di = $app->getLocator(); $view = $di->get('view'); $url = $view->plugin('url'); $url->setRouter($app->getRouter()); $view->plugin('headTitle')->setSeparator(' - ') ->setAutoEscape(false) ->append('Application'); $this->view = $view; return $view; } }
Hors ligne
Pages: 1