zend-framework2

Using PhpRenderer directly with child views in ZF2

让人想犯罪 __ 提交于 2019-12-06 14:13:56
When sending out e-mails in Zend Framework 2, I want to use view script templates such that I can leverage a layout for my various e-mail templates. The idea is that I have a layout which has the shared markup and echoes out content somewhere. Exactly how layouts work in general. To accomplish this, I am trying to add a child view model to my layout view model and render it with the PhpRenderer . public function someMethod() { $child = new ViewModel(); $child->setTemplate('test-template'); $layout = new ViewModel(); $layout->setTemplate('email-layout'); $layout->addChild($child, 'content');

ZF2 Re-starting service manager key

一世执手 提交于 2019-12-06 13:52:57
I have a database adapter stored in my service manager called "dbAdapter". I am looking for a way to disconnect and then re-connect to this adapter using a slightly different configuration, possibly several times. The reason is that I have many customers who's database structure is 100% is the same. I am writing a cron job that will do maintance on each database but it has to connect to the first one, do its thing, drop the connection and connect to the next one...until it is out of databases. I was looking through the source but I could only find a single protected method in Zend

Zend Framework 2: How to get ServiceLocator in validation class

扶醉桌前 提交于 2019-12-06 12:57:54
I would like to get ServiceLocator in my validation class. I tried get it from Controller instance but it returns null. MyValidation.php namespace Register\Validator; use Zend\Validator\AbstractValidator; use Register\Controller\RegisterController; class MyValidation extends AbstractValidator { /* code... */ function isValid($value) { $controller = new RegisterController(); $sm = $controller->getServiceLocator(); $tableGateway = $sm->get('Register\Model\RegisterTable'); $tableGateway->myValidationMethod($value); } } Module.php public function getServiceConfig() { return array( 'factories' =>

Zend Framework 2 - Pagination

谁都会走 提交于 2019-12-06 12:44:31
How can i get the page details in controller's action? I have used the album's pagination. $iteratorAdapter = new \Zend\Paginator\Adapter\Iterator($this->getAlbumTable()->fetchAll()); $paginator = new \Zend\Paginator\Paginator($iteratorAdapter); $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage(2); return new ViewModel(array( 'paginator' => $paginator )); I had tried to get by using the method getPages(). $iteratorAdapter = new \Zend\Paginator\Adapter\Iterator($this->getAlbumTable()->fetchAll()); $paginator = new \Zend\Paginator\Paginator($iteratorAdapter); $paginator-

ZF2 use database table model in view helper

孤人 提交于 2019-12-06 12:08:10
To show an database count in my layout.phtml I want to use the view helper to render ths count (set in an db field). How do I use my database model in a view helper? Helper: namespace Application\View\Helper; use Zend\View\Helper\AbstractHelper; class CountHelper extends AbstractHelper { protected $count; public function __invoke() { return $this->count(); } public function setTableCount($sm, $myCountTable) { $this->count = $sm->get($myCountTable)->getCount(); return $this->count; } } Module public function getViewHelperConfig() { return array( 'factories' => array( 'CountHelper' => function(

How to create a generic module/controller/action route in Zend Framework 2?

人盡茶涼 提交于 2019-12-06 12:05:29
问题 I would like to create a generic module/controller/action route in Zend Framework 2 to be used with ZF2 MVC architecture. In ZF1 the default route was defined like /[:module][/:controller][/:action] where module would default to default , controller would default to index and action to index . Now, ZF2 changed the way modules are intended, from simple groups of controllers and views, to real standalone applications, with explicit mapping of controller name to controller class. Since all

Use another module in our custom helper in zend framework 2

狂风中的少年 提交于 2019-12-06 11:59:44
I want to use WebinoImageThumb moudle in my custom helper , but when I want to create an instance of this module in helper factories I got this error : Zend\View\HelperPluginManager::get was unable to fetch or create an instance for WebinoImageThumb But I can access to an instance in my controller without any problem. This is the code I get error in : public function getViewHelperConfig() { return array( 'factories' => array( 'ImageLib' => function ($sm) { $WebinoImageThumb = $sm->get('WebinoImageThumb'); return new \Base\view\helper\ImageLib($WebinoImageThumb); } ) ); } The question that's

ZF2 maintenance page

旧巷老猫 提交于 2019-12-06 11:43:30
问题 I try to set up a maintenance page with ZF2 but it's not working. I put a maintenance.html page in public folder (www) and in my onbootstrap function I've got the following code : $config = $e->getApplication()->getServiceManager()->get('Appli\Config'); if($config['maintenance']) { $response = $e->getResponse(); $response->getHeaders()->addHeaderLine('Location', '/maintenance.html'); $response->setStatusCode(503); return $response; } I enter the if cause $config['maintenance'] is true but it

ZF2 fileprg with files in collection

谁都会走 提交于 2019-12-06 11:28:12
I can't get fileprg plugin to work with the files in a collection. I am trying to upload multiple files using FormCollections , but in $form->getData() there is no key related to my collection or the files . I tested the form and fileprg with simple file input (in the same form) and it worked uploaded/renamed and it was in the $form->getData() . what am i missing ? is there anything special to be done with the collections to get it to work ? In the file \Zend\Mvc\Controller\Plugin\FilePostRedirectGet the two functions you want to look at are getNonEmptyUploadData (that is supplying a callback

How to set query parameter with redirect()

霸气de小男生 提交于 2019-12-06 11:27:17
I would like to set a query parameter when redirecting. I tried this: $this->redirect()->toRoute('login/default', array('action' => 'forgotPassword', 'foo' => 'bar')); It redirects to: /login/forgotPassword Instead of where I would like to redirect which is: /login/forgotPassword?foo=bar The query parameter belongs to the third parameter of the URL-Methods. $this->redirect()->toRoute( 'login/default', array( 'action' => 'forgotPassword' ), array( 'query' => array( 'foo' => 'bar' )) ) Plus. To redirect a "access" or login, form you can use: if (!$controller->identity()) { $sm = $controller-