zend-framework2

How to get baseUrl in ZF2 controller?

*爱你&永不变心* 提交于 2019-12-03 08:53:59
问题 In my zf2 controller I want to retrieve the application base URL (for example http://domain.com ). I tried the following call but it returns an empty string. $this->request->getBasePath(); How can I then get the http://domain.com part of URL in my controller? 回答1: I know this is not the prettiest way of doing it but, hey, it works: public function indexAction() { $uri = $this->getRequest()->getUri(); $scheme = $uri->getScheme(); $host = $uri->getHost(); $base = sprintf('%s://%s', $scheme,

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

荒凉一梦 提交于 2019-12-03 08:46:22
问题 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? 回答1: 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

Why use the Service Manager in Zend Framework 2?

人盡茶涼 提交于 2019-12-03 08:27:54
问题 lets say i have a service: namespace Helloworld\Service; class GreetingService { public function getGreeting() { if(date("H") <= 11) return "Good morning, world!"; else if (date("H") > 11 && date("H") < 17) return "Hello, world!"; else return "Good evening, world!"; } } and i create an invokable for it public function getServiceConfig() { return array( 'invokables' => array( 'greetingService' => 'Helloworld\Service\GreetingService' ) ); } then in my controller i could do: public function

Zend Framework Multi Language Integration Steps

陌路散爱 提交于 2019-12-03 08:27:22
I am new to zend framework2 and I am working on a site with multi language integration. Please give me the idea about, how the builtin library and translation file should be configured, and how its can be called from view file ZF2 has already integrated I18n tools. How to integrate it module.config.php 'translator' => array( 'locale' => 'en_US', 'translation_file_patterns' => array( array( 'type' => 'gettext', 'base_dir' => __DIR__ . '/../language', 'pattern' => '%s.mo', ), ), ), Files *.mo Following previous step, create a folder and add your en_US.mo (for example) using Poedit (simple and

Entity exist validation in Zend Framework 2 with Doctrine 2 using inputfilter in entity

安稳与你 提交于 2019-12-03 08:20:49
I have been building my all validation in Entity class like this... class User { protected $inputFilter; public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array( 'name' => 'username', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( 'name' =>'NotEmpty', 'options' => array( 'messages' => array( \Zend\Validator\NotEmpty::IS_EMPTY => 'User name can not be empty.' ), ), ), array( 'name' =>

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

…衆ロ難τιáo~ 提交于 2019-12-03 08:02:25
问题 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

Can I render view without returning it in action controller in zend framework 2?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 07:16:28
Now I am doing so: public function indexAction() { ... $view = new ViewModel(array( 'foo' => 'bar', )); return $view; } The problem is that I want to do something after $view rendering and before layout rendering: public function indexAction() { ... $view = new ViewModel(array( 'foo' => 'bar', )); $layout = $this->layout(); $layout->content = $view->render(); ... // here I want to do some important action ... $html = $layout->render(); return $this->getResponse()->setContent($html); } But there is no method render(). In ZF1 I could render view: $view = new Zend_View($data); $html = $view-

How to create form inputs/elements in ZF2

流过昼夜 提交于 2019-12-03 06:55:34
EDIT : My main question has now become 'How do I get the ServiceManager with the doctrine entity manager into the hands of my form, element, and input classes in some clean way?' Read on to see the full post. I'm going to try and ask by example here so bear with me. Let me know where I'm going wrong/right or where I could improve I'm trying to create a registration form. I could use ZfcUser module but I want to do this on my own. I'm using ZF2 with Doctrine2 as well so that leads me away from that module a bit. My strategy was this, Create a form class called registration form Create separate

How to create custom form element in Zend Framework 2?

試著忘記壹切 提交于 2019-12-03 06:21:00
How can I in ZF2 create custom form element with custom validator? I want to create custom category picker that uses jQuery and content of this element should be rendered from phtml script. In ZF1 it was quite easy but in ZF2 I don't know from where to start. A form element must implement a Zend\Form\ElementInterface . A default class is the Zend\Form\Element which you can use as a base form: <?php namespace MyModule\Form\Element; use Zend\Form\Element; class Foo extends Element { } CUSTOM VALIDATOR You can let the element directly assign a custom validator. Then you must implement the Zend

How does Zend Framework 2 render partials inside a module?

丶灬走出姿态 提交于 2019-12-03 06:03:21
I've got something like this for my directory structure inside a module: Api ├── Module.php ├── config │ └── module.config.php ├── src │ └── ( ..etc ..) └── view ├── api │ └── api │ └── index.phtml └── partial └── test.phtml Then, I'm doing this: <?= $this->partial('partial/test.pthml', array()); ?> However, I get: 05-Jun-2012 14:56:58] PHP Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "partial/test.pthml"; resolver could not resolve to a file' in /Users/jeff/web/n/vendor/zendframework