Skip to content

zend framework 2 (zf2) - where to find the default manager config key names

For exampe, you want to add your own controller plugin in the module.config, do you know the key name out of the box? Me neither, but i know where to look.
Open the ModuleManagerFactory and serch for view_helpers to get the spot where and how the configuration array key names are defined.
After this, the adding of your controller plugin is a solveable task :-).

php - zend framework 2.1 released

The zend framework 2 girls and guys (hopefully there are some girls) have released their first minor update called 2.1.0. Congratulations from my side to you guys. While reading the release notes my face starts smiling when i've reached the "new tooling sections". Why? Because of the following entries.

- Skeleton application creation - Module creation within a skeleton - Autoloader classmap creation - ZF2 installation to a directory
I can't wait to play around with that. There is also a great looking howto out there in the web. Also quite exciting:
New Zend\Permissions\Rbac component, providing Role-Based Authorization Controls. These complement our existing Zend\Permissions\Acl component, providing another mechanism for providing authorization for your applications. We have Kyle Spraggs to thank for this addition.

howto - zend framework 2 - form multilingual error messages and labels

Since the first time working with the new zend framework 2 form elements, i like it. Everybody who had the pleasure to deal with the form class from zend framework 1 will agree on that. But after a little bit of playing around with it, i had to build a form that works with multiple languages and has a lot of mandatory fields. Since you are injecting a filterclass with validators into the form, you have to create the error message inside the filter class and like:

//part of a form filter constructor $this->add( array( 'name' => 'name', 'filters' => array( array( 'name' => 'StringTrim' ) ), 'validators' => array( array( 'name' => 'NotEmpty', 'options' => array( 'messages' => array( \Zend\Validator\NotEmpty::IS_EMPTY => 'I am the error message that should be multilingual.' ) ) ) ) ) );
So my first idea was to inject a translator. Since you are using a "MyMagicFormFactory" to create the form, you can easily inject the translator (or the servliceLocator if you want to). But after a few thoughts, i figured out that the error message itself is totally wrong on that place, for my point of view. I thing a form as well as a filter is not responsible for a human readable error message. Thats why i moved/reset the definition of the error message and handle it in the template. Of course, i am also using the translator but now only in the view layer. By the way, i will deal the same way with the labels for each form element.

So the simple question is how to deal with it? To keep it simple, i will not use the translator inside the following example. Assuming you a form with a input field for an email address. You can deal with it the following way.

<?php echo $this->form()->openTag($this->form); ?> <dl> <dt> <!-- we don't use the method ->getOption('lable') since we want to deal the multiple languages inside the template --> Your mail address </dt> <dd> <?php echo $this->formEmail($this->form->get('email)); $messages = $this->form->get('from')->getMessages(); //take a look inside the $messages since it is an array with keys like 'isEmpty' // if you want to create error messages by key, thats the way you can handle this. if (!empty($messages)) { echo '<label for="from" class="error">Please insert a valid email address.</lable>'; } ?> </dd> </dl>
Enjoy working with zend framework 2 :-).

web - Zend Framework 2 ServiceManager

english I found a great summary about available service manager features.

Invokables An invokable is simply a fully qualified class name, provided to the SM as a string. When requested, it will simply be instantiated with new $invokableClass();. [...] Factories A factory is either a PHP callable, an object, or the fully qualified class name of a class implementing Zend\ServiceManager\FactoryInterface. Factories are used to perform any setup or dependency injection required for the object being requested. [...] Aliases An alias simply points one service name to another and they can be recursive. This may seem pointless at first, but aliases actually play a very important role in a modular environment. [...] Initializers An initializer is either a closure, an object, or the fully qualified class name of a class implementing Zend\ServiceManager\InitilizerInterface. Any object pulled from a service manager is ran through the registered initializers which can perform additional initialization tasks. [...] Configuration Classes A configuration class that implements Zend\ServiceManager\ConfigInterface. Config classes simply know how to configure an instance of the SM, potentially setting several factories, invokables, initializers, etc. [...] Shared Services Anything placed in the SM can be either shared or not shared. If shared, the SM will create an instance of the requested service object the first time it is requested, and on subsequent requests, return that same exact instance. If shared is set to false for a service, the service manager will create a new service. By default, all services are set to shared. [...] Abstract Factories If a SM is asked for a service which it cannot locate, it will then query the registered abstract factories to see if any of them are able to create the requested object. An abstract factory is either a fully qualified class name as a string or instance of an object that implements Zend\ServiceManager\AbstractFactoryInterface. [...] Peering Service Managers The service manger introduces a concept of peering. Each service manager can have “peers”, or rather, a stack of one or more other service managers which can also be used when a service is pulled from the SM. [...]
source Quick start service managers in your application Great survey, isn't it?

deutsch Auf der Suche nach einer Erklärung über das Wort "invokable" fand ich einen Eintrag, der eine Übersicht über vorhandene Service Manager Funktionen gab. Um das Wissen auch in meiner Muttersprache weiter zugeben, folgt anschließend die Übersetzung der weitern oben zitierten, englischen Zeilen.

Invokables Ein "invokable" ist ein vollqualifizierter Klassenname, welcher dem ServiceManager als Zeichenkette zur Verfügung bereitgestellt wird. Falls verlangt, wird eine neue Instanz dieser Klasse mit Hilfe von "new $invokableClass();" erzeugt. [...] Factories Eine "factory" (Fabrik) kann eine PHP abrufbare, ein Object, oder ein vollqualifizierter Klassenname einer Klasse sein, welche die Schnittstelle "Zend\ServiceManager\FactoryInterface" implementiert. Fabriken werden genutzt um jegliche Einrichtung (Setup) oder Abhängigkeitsinjektion (dependency injection) für die Instanziierung einer Klasse zu realisieren und zentralisieren. [...] Aliases Eine "alias" (alternative Bezeichnung) zeigt einfach auf einen anderen Dienst und kann rekursiv sein. Wirken Aliases am Anfang als unnütz, können sie bei einer modularen Umgebung eine große Rolle spielen. [...] Initializers Ein "initializer" (Initialisierungsprogramm) ist entweder ein Closure, ein Object oder ein vollqualifizierter Klassenname einer Klasse, welche die Schnitstelle "Zend\ServiceManager\InitilizerInterface" implementiert. Ein Objekt, welches vom ServiceManager kommt, durchläuft die registrierten Initialisierungsprogramme, welche weitere Initialisierungsaufgaben vornehmen können. [...] Configuration Classes Eine "configuration class" (Einstellungsklasse) implementiert die Schnittstelle "Zend\ServiceManager\ConfigInterface". Einstellungsklassen wissen, wie sie den ServiceManager konfigurieren, setzen etwaig Fabriken, "invokables", Initialisierungsprogramme usw. [...] Shared Services Alles, was in den ServiceManager vorhanden ist, kann geteilt werden. Wenn ein Dienst geteilt ist, wir der ServiceManager eine Instanz des gewünschten Objects erstellen und zurückgeben. Wurde bereits eine Instanz erstellt, gibt der ServiceManager diese Instanz bei einer enreuten Anfrage wiederrum zurück. Falls ein Dienst nicht geteilt werden darf, erstellt der ServiceManager bei jeder Nachfrage eine neue Instanz der Klasse. Von Haus aus sind Dienste geteilt. [...] Abstract Factories Falls ein ServiceManager nach einem Dienst gefragt wird, den er nicht finden kann, wird er alle vorhandenen, abstrakten Fabriken anfragen um das gewünschte Objekt zu erstellen. Eine abstrakte Fabrik ist entweder ein vollqualifizierter Klassenname oder eine Instanz eines Objekts, welches die Schnittstelle "Zend\ServiceManager\AbstractFactoryInterface" implementiert. [...] Peering Service Managers Der ServiceManager hat das Konzept des "peering" (Späherei/Umherschauens/Gleichrangigkeit) eingeführt. Jeder ServiceManager kann einen, oder eine Sammlung von, "Gleichgestellten"/"Spähern" ServiceManagern besitzen, welche ebenfalls genutzt werden können, wenn ein Dienst vom ServiceManager angefordert wird. [...]
Quelle Schnellstart Service Managers in deiner Anwendung Übersetzungsfehler korrigiere ich gern.