zend-framework2

Implementing a password validator for zf2

五迷三道 提交于 2019-12-21 19:28:13
问题 What is a good approach to write a password validator that validates two inputs (must be eqeal) and how would you integrate that into a zf2 form. 回答1: There is an "Identical" validator that check two fields to be equal, it can be used in the following way in form constructor: $this->add(array( 'name' => 'password', // add first password field /* ... other params ... */ )); $this->add(array( 'name' => 'passwordCheck', // add second password field /* ... other params ... */ 'validators' =>

ZF2 toRoute with https

倾然丶 夕夏残阳落幕 提交于 2019-12-21 17:28:04
问题 We're using Zend Framework 2 and use toRoute within our controllers to redirect to various locations, for example $this->redirect()->toRoute('home'); . Is there anyway to have this redirect to https instead of http using this method or an alternative method? Thank you! 回答1: In order to use https in your route you need to use the Zend\Mvc\Router\Http\Scheme router. Specifying the configuration for such route is not very different from the other routes. You need to specify the route type as

Routing Zend Framework 2 Language in url

纵饮孤独 提交于 2019-12-21 17:23:42
问题 For my application translation I would like to use a language structure e.g.: site.com (english) site.com/de/ (german) site.com/fr/ (france) site.com/nl/ (dutch) etc.. I can do this easily with the router option in Literal as '[a-z]{2}' but I want to exclude languages I do not support, e.g. site.com/it/ if it is not supported I want a 404. I tried to fix this with regex (adding supported languages) but something (I do not know) went wrong. Thanks in advance! 'router' => array( 'routes' =>

ZF2 SessionManager usage

大兔子大兔子 提交于 2019-12-21 12:58:56
问题 I am new to ZF2 and not quite used to how to do stuff. I want to use session to keep track of an user (remember me). I had this code in one part of my class: $sessionManager = new \Zend\Session\SessionManager(); $sessionManager->rememberMe($time); // i want to keep track of my user id too $populateStorage = array('user_id' => $user->getId()); $storage = new ArrayStorage($populateStorage); $sessionManager->setStorage($storage); Ok, so far so good. When i try: var_dump($sessionManager-

What exactly is the user state in ZfcUser?

妖精的绣舞 提交于 2019-12-21 12:27:16
问题 Can anybody tell me, what the "user state" in the ZfcUser is doing exactly and why we may need it? What does this user state mean (I assume it's not the role meant by it)? 回答1: Basically it's a flag to indicate the state of a user. Sometimes you need to be able to disable users, or otherwise affect their 'state' without actually deleting them from the table. That's what the state column is intended for if you use such a system. As a simple example, think of a temporarily banned user on a

Zend Framework 2 Redirect

◇◆丶佛笑我妖孽 提交于 2019-12-21 07:57:21
问题 How can I redirect to another module? return $this->redirect()->toRoute(null, array( 'module' => 'othermodule', 'controller' => 'somecontroller', 'action' => 'someaction' )); This doesn't seem to work, any ideas? 回答1: This is how I redirect from my Controller to another Route: return $this->redirect()->toRoute('dns-search', array( 'companyid' => $this->params()->fromRoute('companyid') )); Where dns-search is the route I want to redirect to and companyid are the url params. In the end the URL

ZF2 config from module with no controllers

耗尽温柔 提交于 2019-12-21 05:44:05
问题 I'm currently in the process of building a module to serve as a re-usable library throughout multiple projects, however due to it being a library there isn't a need for a controller. What I'm trying to do for instance is create a zf2 module for Marketo soap API for instance. User adds their keys and wsdl location in /ROOT/config/autoload/local.php. The configuration would include something like 'marketo'=>array(), Now the problem that I'm having is I want to give myself and others using the

How to configure doctrine extensions in Zend Framework 2?

家住魔仙堡 提交于 2019-12-21 05:15:45
问题 I have added this line to my composer.json: "gedmo/doctrine-extensions": "dev-master" And this is inside my module's module.config.php: 'doctrine' => array( 'driver' => array( __NAMESPACE__ . '_driver' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'), ), 'orm_default' => array( 'drivers' => array( __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver' ), ), ), ), Then I want to use

Set Different Layout for Different Module in Zend Framework 2?

自古美人都是妖i 提交于 2019-12-21 05:12:12
问题 I have two module Student and Teacher. I also have two different layout one is studentlayout.phtml and another is teacherlayout.phtml How can I set studentlayout for Student module and teacherlayout for Teachermodule? As Per Sam's answer .Thanks Its working fine. but i also want to set two different layout For Teacher. So i add following code in my main config file for project: 'module_layouts' => array( 'Teacher' => array( 'default' => 'layout/adminlayout', 'login' => 'layout/loginlayout', )

Posting Form Data to ZF2 Controller With Ajax

爷,独闯天下 提交于 2019-12-21 05:09:10
问题 EDIT- I have posted the answer below. The question is that I don't understand how/where ZF2 posts form data when a submit button is pressed. So, when I do if ($this->getRequest()->isPost()){ after the ajax call below, it tells me that no data has been posted. When I do the above isPost() if statement it works perfectly when I hit the submit button, telling me the data has been posted and subsequently telling me that the form data is valid. Here is the ajax call- <script> $.ajax({ url: urlform