zend-framework2

Validation in Zend Framework 2 with Doctrine 2

我与影子孤独终老i 提交于 2019-11-30 23:42:29
I am right now getting myself more and more familiar with Zend Framework 2 and in the meantime I was getting myself updated with the validation part in Zend Framework 2. I have seen few examples how to validate the data from the database using Zend Db adapter, for example the code from the Zend Framework 2 official website: //Check that the username is not present in the database $validator = new Zend\Validator\Db\NoRecordExists( array( 'table' => 'users', 'field' => 'username' ) ); if ($validator->isValid($username)) { // username appears to be valid } else { // username is invalid; print the

Zend Framework 2 filter / validate array of contents

安稳与你 提交于 2019-11-30 23:24:11
How do I apply a filter to a field element with the contents of an array? For example: $this->add( "name" => "tags", "type" => "text", "filter" => array( array("name" => "StripTags"), array("name" => "StringTrim") ) ); $tags[0] = "PHP"; $tags[1] = "CSS"; If I attempt to filter I receive an error saying a scalar object is excepted, array given. This isn't really possible at this time. Your best bet is to use a Callback filter and filter each Item individually. Something like this $this->add( "name" => "tags", "type" => "text", "filter" => array( array("name" => "Callback", "options" => array(

how to disable inArray validator forms in zend framework2

情到浓时终转凉″ 提交于 2019-11-30 23:01:38
i use this in my Form: $this->add(array( 'type' => 'Zend\Form\Element\Select', 'name' => 'county', 'registerInArrayValidator' => false, 'attributes' => array( 'id' => 'county', 'options' => array( //'null'=>'[Select county]', ), ), 'options' => array( 'label' => 'county', ), )); and set value county field with js. after validation, i get error : haystack option is mandatory Add the disable_inarray_validator to the options: $this->add(array( ... 'options' => array( 'disable_inarray_validator' => true, 'label' => 'county', ), )); In https://github.com/zendframework/zf2/blob/master/library/Zend

How to remove a validator from a Form Element / Form Element ValidatorChain in Zend Framework 2?

一个人想着一个人 提交于 2019-11-30 22:01:53
I read this question on SO: " how to disable inArray validator forms in zend framework2 " and was trying to find it out, but couldn't find any way to detach/remove the InArray Validator. But InArray is just a validator. So how can remove a validator from the validator list of a form element? I can get the validators: $myElement = $form->getInputFilter()->get('city'); $validatorChain = $cityElement->getValidatorChain(); $validators = $validatorChain->getValidators(); and maybe can then unset the array element with the validator, I want to remove, and then pass the result array back to the Input

Multiple namespaces under same module in ZF2

℡╲_俬逩灬. 提交于 2019-11-30 21:27:52
I'm having trouble configuring multiple namespaces/classes under same module. For example, I have a module called "Account", in which I'd like to include all account related classes (companies: 'accounts', users: 'users', external api: 'api' etc.. ). Module structure looks like this.. /Account - Module.php - /config - /view - /src - /Account - /Controller (AccountController.php) - /Form (AccountForm.php) - /Model (Account.php + AccountTable.php) - /User - /Controller (UserController.php) - /Form (UserForm.php) - /Model (User.php + UserTable.php) - /Api - Api.php (simple class) Being new to ZF2

Zend Framework 2 “Zend Tool Missing” in bin folder

ε祈祈猫儿з 提交于 2019-11-30 20:50:17
问题 im newbie in frameworks, but i had no difficulty installing etc the zend 1.x versions. But with ZF2 cant really figure out.... Any recource telling me creating a project using the zend tool i.e. zf.bat or zf.sh from bin directory, but there's none of them in the zf2 bin folder in contrast to zf1. The only files present are autloader_example.php autloader_examples.php classmap_generator.php createAuoloadTestClasses.php docbook_skeleton.php plugin_generator.php can anyone help me anyhow... neet

How can I use ZF1 $this->action in ZF2?

痴心易碎 提交于 2019-11-30 20:32:09
问题 My problem is that in ZF2 missing Action View Helper. How can I use for example in layout.phtml (or in other view)? ZF1: $this->action("index", "index") // call IndexController indexAction ZF2: ??? How can i solve this? The problem solved!!! ;) http://www.michaelgallego.fr/blog/?p=223 回答1: First you need to write a custom helper like this: https://github.com/AlloVince/eva-engine/blob/master/vendor/Eva/View/Helper/Action.php Maybe you need to change the namespace to fit your project, Then

how to create a factory in zend framework 2?

落花浮王杯 提交于 2019-11-30 19:48:32
in my Module.php i have the fallowing methods that i would like to move them in a factory class so that i wont clutter the Module class : public function getControllerConfig() { return array( 'factories' => array( 'account-index' => function ($controllerManager) { $serviceManager = $controllerManager->getServiceLocator(); $accountService = $serviceManager->get('account-service'); return new Controller\IndexController($accountService); } ) ); } public function getServiceConfig() { return array( 'factories' => array( 'account-service' => function ($serviceManages) { return new Service\Account; }

Zend Navigation and RBAC

China☆狼群 提交于 2019-11-30 19:05:08
问题 I am developing a ZF2 based site. I have a main navigation which stays same regardless of the visitor/user status. Need to add another component/nav, which will depend on the user's status and role. For a visitor the items will be Register Login EN (Actually a drop-down, with other available language) For a logged-in normal user, it will display Profile Logout EN (Language selector as mentioned above) And for some users with specific roles/permission there will be additional items I want to

How to set db adapter to Validator RecordExists in Zend Framework 2

一个人想着一个人 提交于 2019-11-30 18:56:40
问题 I'm trying to add validator RecordExists to my form but I get error 'no db adapter present'. How can I set db adapter to this validator? I use examples from skeleton application and I'm trying to do something like this (yes, I know that $dbAdapter is undefined :) I'm searching solution how to change this variable to db adapter resource ): namespace Album\Model; use Zend\InputFilter\Factory as InputFactory; // <-- Add this import use Zend\InputFilter\InputFilter; // <-- Add this import use