zend-framework2

How does Zend Framework 2 render partials inside a module?

无人久伴 提交于 2019-12-03 17:07:27
问题 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

MasterSlaveFeature How-To

半腔热情 提交于 2019-12-03 16:27:24
I currently have my Db Models using AbstractTableGateway and all my select/insert/update/delete queries are working just fine. But now I would like to add the MasterSlaveFeature and I'm a bit confused on how to do this. The documentation doesn't exactly give a good example: http://zf2.readthedocs.org/en/latest/modules/zend.db.table-gateway.html#tablegateway-features I currently have this setup: namespace Login\Model; use Zend\Db\TableGateway\Feature\MasterSlaveFeature; use Zend\Db\TableGateway\Feature\FeatureSet; use Zend\Db\TableGateway\AbstractTableGateway; use Zend\Db\Sql\Select; use Zend

ZF2 Use Redirect in outside of controller

房东的猫 提交于 2019-12-03 16:17:36
I'm working on an ACL which is called in Module.php and attached to the bootstrap. Obviously the ACL restricts access to certain areas of the site, which brings the need for redirects. However, when trying to use the controller plugin for redirects it doesn't work as the plugin appears to require a controller. What's the best way to redirect outside from outside of a controller? The vanilla header() function is not suitable as I need to use defined routes. Any help would be great! Cheers- Jurian Sluiman In general, you want to short-circuit the dispatch process by returning a response. During

How to validate a checkbox in ZF2

你。 提交于 2019-12-03 15:55:28
I've read numerous workarounds for Zend Framework's lack of default checkbox validation. I have recently started using ZF2 and the documentation is a bit lacking out there. Can someone please demonstrate how I can validate a checkbox to ensure it was ticked, using the Zend Form and Validation mechanism? I'm using the array configuration for my Forms (using the default set-up found in the example app on the ZF website). Try this Form element : $this->add(array( 'type' => 'Zend\Form\Element\Checkbox', 'name' => 'agreeterms', 'options' => array( 'label' => 'I agree to all terms and conditions',

Get local value in layout or view in Zend Framework 2

≡放荡痞女 提交于 2019-12-03 15:50:01
How can we get local value (i.e: 'en' or 'en_US', 'de' etc) in layout.phtml or views in Zend Framework 2? My local setting are exactly same as explained here <?php namespace FileManager; use Zend\Mvc\ModuleRouteListener; class Module { public function onBootstrap($e) { $translator = $e->getApplication()->getServiceManager()->get('translator'); $translator ->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE'])) ->setFallbackLocale('en_US'); } //... } I want to get local value something like this: $locale = $this->translate()->getLocale(); // <-- It's not working anyway I need to

Best and secure way to send parameters in URL

此生再无相见时 提交于 2019-12-03 15:14:51
I am working on a website in which there would be functionalities to update and delete data on the basis of id. Now the thing I am worried about is like my url would be www.example.com/public/controller/action/1 if the action would be delete , any person can change id from 1 to 2 in url and the data with id 2 would get deleted. What would be the best way to keep the flow secure. I am using Zf2 and Doctrine2... Any suggestions please !!! And moreover I am keeping ids hidden in fields, anybody can use firebug to change the value in fields, is there any way to protect data from that too? Would

Faster, better, and more efficient type hinting for PHP Storm with service locators

自闭症网瘾萝莉.ら 提交于 2019-12-03 15:06:12
问题 I have been looking for a way to do this for months. I am one of those developers that loves autocompletion. For every Service Locator call in zend framework 2 I type hint with the following: Without global hinting file /** @var \Module\Service\SuperService $superService */ $superService => $this->getServiceLocator()>get('\Module\Service\SuperService'); $superService->coolFunction(); This works, but the code can get messy when you start getting 2-4 Services in a single Controller. I am trying

ZF2: how do I get ServiceManager instance from inside the custom class

时光毁灭记忆、已成空白 提交于 2019-12-03 14:05:10
I'm having trouble figuring out how to get ServiceManager instance from inside the custom class. Inside the controller it's easy: $this->getServiceLocator()->get('My\CustomLogger')->log(5, 'my message'); Now, I created a few independent classes and I need to retrieve Zend\Log instance inside that class. In zend framework v.1 I did it through static call: Zend_Registry::get('myCustomLogger'); How can I retrieve the My\CustomLogger in ZF2? Make your custom class implement the ServiceLocatorAwareInterface . When you instantiate it with the ServiceManager, it will see the interface being

Create a doctrine repository with dependencies (dependency injection) in ZF2

自作多情 提交于 2019-12-03 13:49:14
问题 I want to make a repository with hard dependencies. I found this blog post by Jurian Sluisman but he suggests getting the repository from the service manager and injecting it into the service where needed. It would be much better if I would be able to get my custom repositories with injected dependencies like normally from my EntityManager or ObjectManager instance by using the getRepository method: $objectManager->getRepository('My\Entity\Class'); How can I use constructor injection in my

Zend Framework 2 module share variables between controllers onBootstrap

為{幸葍}努か 提交于 2019-12-03 13:38:45
问题 Is it possible to create variables or even shared objects (like DB adapter) at in Module.php for use in all view controllers? (Zend Framework 2) For example: class Module { public function onBootstrap(MvcEvent $e) { $moduleConfig = $e->getServiceManager()->get('Config') } } And in a controller, somehow access using: $this->moduleConfig['db'] In above I know that would just be the config array for the db adapter, but how would that even work? I see that one can do this in a controller action: