zend-framework2

How to use InputFilterManager to construct custom InputFilters in Zf2

↘锁芯ラ 提交于 2019-12-03 02:59:58
ZF2 documentation says following on defult services documentation ; InputFilterManager, mapping to Zend\Mvc\Service\InputFilterManagerFactory. This creates and returns an instance of Zend\InputFilter\InputFilterPluginManager, which can be used to manage and persist input filter instances. I have a custom zf2 inputfilter class and i'm adding filters and validators inside init() method like following; namespace Application\Filter; use Zend\InputFilter\InputFilter; class GlassFilter extends InputFilter { public function init() { $this->add(array( 'name' => 'glassname', 'required' => true,

ZF2 how to get entity Manager from outside of controller

喜夏-厌秋 提交于 2019-12-03 01:41:14
we can access entity manager within controller using $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); but how can we access entity manager singleton instance in rest of the project in Zendframework 2. The 'right' way to do it is use a factory to inject the entity manager into any classes that need it. Classes, other than factories, shouldn't really be aware of the ServiceLocator. So, your module config would look like this: 'controllers' => array( 'factories' => array( 'mycontroller' => 'My\Namespace\MyControllerFactory' ) ) Then your factory class would look something

How to get Zend\\Db\\Adapter instance from within a Model? (ZF2)

家住魔仙堡 提交于 2019-12-03 00:50:01
I'm creating abstract models for managing database entities - I already have EntityAbstract , EntitySetAbstract and a ManagerAbstract models. In my ManagerAbstract model I need a Zend/Db/Adapter instance in order to create a Zend\Db\TableGateway . How could I pull the main instance of the adapter to my ManagerAbstract ? In ZF1 I could have achieved this with Zend_Registry. If this isn't the right way of doing things in ZF2, I would love to hear the correct way to this kind of things. Thanks! Use the Dependency Injection Container, Zend\Di . The ZfcUser project does this if you want to poke

How can/should Zend Framework 2 be included to a Git versioned project?

情到浓时终转凉″ 提交于 2019-12-02 23:04:40
How should the version controlling of a Zend Framework 2 project be managed? Is there a best practice / "standard approach" for this? Is "submodule" the right keyword? A Zend Framework 2 Project is usually a lightweight skeleton application with various installed modules, which usually are on separate dedicated repositories. The main repository isn't usually affected by many changes, so you can create a git repository (fork of ZendSkeletonApplication ) for it. While the modules are more relevant and require some care, the skeleton application usually changes only in a couple details over the

Zend FrameWork 2 Get ServiceLocator In Form and populate a drop down list

余生颓废 提交于 2019-12-02 21:58:17
I need to get the adapter from the form, but still could not. In my controller I can recover the adapter using the following: // module/Users/src/Users/Controller/UsersController.php public function getUsersTable () { if (! $this->usersTable) { $sm = $this->getServiceLocator(); $this->usersTable = $sm->get('Users\Model\UsersTable'); } return $this->usersTable; } In my module I did so: // module/Users/Module.php public function getServiceConfig() { return array( 'factories' => array( 'Users\Model\UsersTable' => function($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $uTable = new

Passing forms vs raw input to service layer

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 21:39:21
问题 Is it better to validate a form and pass its filtered input to the service layer, or to pass the raw input to the service layer, and have the service validate the input (with or without a form instance)? Obviously, if it's the latter, the controller still needs access to the form so that it can be sent to the view for rendering. If so, would you just access the form via the service ($service->getRegistrationForm())? See also: Dependency management in Zend Framework 2 MVC applications Factory

Pagination using Doctrine and ZF2

て烟熏妆下的殇ゞ 提交于 2019-12-02 21:15:22
i am trying to implement Pagination Using ZF2 and Doctrine. What i am trying to do here is to fetch data from An associated table lets say 'xyz'. Where as my categories table is doing one to many self referencing on its own PK. MY catgories tables has following feilds ID (PK) Created_at Category_id (self referencing PK) My XYZ table lets say it is called Name table has ID (PK) Category_id(FK) name Detail This is what i am trying to do to fetch data public function allSubcategories($id, $column, $order) { $repository = $this->entityManager->getRepository('Category\Entity\Category');

Query data not show in view in zf2? [duplicate]

心已入冬 提交于 2019-12-02 20:15:50
问题 This question already has an answer here : how to show data from document to index.phtml in zf2? (1 answer) How to get query result in zf2? [duplicate] Closed 5 years ago . I make an index action in which i used doctrine query to select data from calendar table and i want to show data using index.phtml but my data not show only blank page shown,how i show data from controller to view? here is my code: public function indexAction() { $dm = $this->getServiceLocator()->get('doctrine

ZF2: Zend Framework 2 Full URL including host name

孤者浪人 提交于 2019-12-02 19:29:43
In my view I need to draw full URL. Like this: http://hostename.com/default/url When I try to use $this->url('default', array(1,2,3)) I get only /index/get/ . Is there any Zend method to het host name or I have to use $_SERVER['HTTP_HOST'] instead? You can use the option force_canonical on the router. All router options go into the third parameter of the url helper: url($route, $params, $options) So you can so something like this: $this->url('myroute', array('id' => 123), array('force_canonical' => true)) I found this article with some interesting ways: 1) without parameters use an empty array

How to generate entities from database schema using doctrine-orm-module and zf2

≯℡__Kan透↙ 提交于 2019-12-02 17:39:14
I am using "doctrine/doctrine-orm-module": "0.7.0" with ZF2. Once I create Entities I usually run following commands to sync and generate database automatically according to my entities. ./vendor/bin/doctrine-module orm:validate-schema ./vendor/bin/doctrine-module orm:schema-tool:create Is there a way to make this process reverse? I mean, Can I generate entities from existing database in mysql? We use a batch script: @ECHO OFF mkdir EXPORT call .\vendor\bin\doctrine-module orm:convert-mapping --force --from-database annotation ./EXPORT/ call .\vendor\bin\doctrine-module orm:generate-entities .