zend-framework2

Zend framework 2 : Add different authentication adapter for two different modules

送分小仙女□ 提交于 2019-12-11 01:16:02
问题 I have two different modules. Now I need to add different authentication mechanism for both modules. So I added event code first module's Module.php's onBootstrap method $listener = $serviceManager->get('First\Service\AuthListener'); $listener->setAdapter($serviceManager->get('First\Service\BasicAuthAdapter')); $eventManager->attach(MvcEvent::EVENT_ROUTE, $listener, 0); and in second module's Module.php's onBootstrap method $listener = $serviceManager->get('Second\Service\AuthListener');

Using PersistentObject from Doctrine in Zend Framework

China☆狼群 提交于 2019-12-11 01:12:25
问题 I have a question for you all. I'm just starting to use Zend Framework after I have used Codeigniter for about 1 year now. I have installed everything and everything is running now. But I have one problem. I want to use Doctrine for my modelling. And I always used the PersistentObject from Doctrine, but I can't seem to get it working. The problem is that I need to pass through a ObjectManager to the PersistentObject. But I can't make it work. Does anybody have any idea how I can pass through

Why to use a Service on ZF2?

好久不见. 提交于 2019-12-11 01:04:51
问题 I'm trying to understand some principles of the ZendFramework 2, and I want to know why to inject services on the ZF2 module.config.php if I can load instance a object using composer autoloader. The same thing for zend factories, why to use this if I can easily implement a Factory class and call it in a controller? 回答1: To be clear up front - the ServiceLocator is not a must use way for creating objects. You still can create objects directly, and in quite a few cases this is a perfectly valid

zf2 tablegateway select columns by column name

こ雲淡風輕ζ 提交于 2019-12-10 23:56:06
问题 <code> $resultSet = $this->tableGateway->select ( function ($select) { $select->columns ( array ( 'id', 'category_name' ) ); } ); tried with above code but it returning all columns, below is the output of return. I need to select id and category_name from database Category\Model\Category Object ( [id] => 2 [category_name] => Cat Two [category_created] => [category_status] => [inputFilter:protected] => ) Category\Model\Category Object ( [id] => 4 [category_name] => Cat one [category_created] =

Zend 2: Where should I put this method that updates a module's nav bar

孤人 提交于 2019-12-10 23:54:38
问题 I previously asked a question about what options are available to inject a navbar (template) automatically on a per module basis. Following one of the suggestions I added a view variable in Myapp/Module/Mymodule/Module.php which is the path of the template public function onBootstrap($e) { $viewModel = $e->getApplication()->getMvcEvent()->getViewModel(); $viewModel->subNav = 'mymodule/mymodule/subNav'; } Then in the Application/view/layout/layout.phtml checked for the presence of this

How to access configs from autoloaded config files in a layout / view script in Zend Framework 2?

独自空忆成欢 提交于 2019-12-10 22:25:38
问题 I would like / have to manage some settings in ZF1 style and provide the view with the infomation about the current environment. /config/application.config.php return array( ... 'module_listener_options' => array( ... 'config_glob_paths' => array('config/autoload/{,*.}{global,local}.php') ) ); /config/autoload/env.local.php return array( // allowed values: development, staging, live 'environment' => 'development' ); In a common view script I can do it over the controller, since the

ZF2 - how to correctly set headers?

不羁的心 提交于 2019-12-10 21:52:47
问题 I have problem with setting headers in ZF2. My code looks like this: public function xmlAction() { $headers = new \Zend\Http\Headers(); $headers->clearHeaders(); $headers->addHeaderLine('Content-type', 'application/xml'); echo $file; // xml file content exit; } But headers are still text/html. I can set the proper header with: header("Content-type: application/xml"); but I would like to do it with Zend Framework. Why code above doesn't work? 回答1: What you are doing is setting headers in a ZF2

Doctrine custom repository with an objectselect form

♀尐吖头ヾ 提交于 2019-12-10 21:31:59
问题 This question is a possible solution for ZF2 Doctrine get manytomany relations with objectSelect, but the question it self is different and not related. I've got a custom repository with this code: class StoreRepository extends EntityRepository { public function getCategories(array $criteria){ return $this->createQueryBuilder("s") ->select('c.id,c.categoryName') ->innerJoin("s.categories", "c", "WITH", "s=:storeid") ->setParameter("storeid", $criteria['storeid']) ->getQuery()->getResult(); }

How to pass options/params to formCollection fieldset in ZendFramework 2?

北慕城南 提交于 2019-12-10 21:17:03
问题 I have a Form which contains a formCollection with a select element that I want to populate with values (from SQL) depending on a POST param. Passing this param from controller to form wasn't a problem but now I can't find a way to set/read that param in target_element of formCollection. Any ideas on how make that work? Here's my code: Controller class MyController extends AbstractActionController{ public function indexAction() { $form = $this->serviceLocator->get('FormElementManager')->get(

Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (Album) could not be initialized

浪子不回头ぞ 提交于 2019-12-10 19:59:38
问题 i have installed skeleton application its working well and i have created New module.Module name 'Album'.after create module trying to run the code i am receiving error. here post my code: module.php <?php namespace Album; use Zend\ModuleManager\Feature\AutoloaderProviderInterface; use Zend\ModuleManager\Feature\ConfigProviderInterface; class Module implements AutoloaderProviderInterface, ConfigProviderInterface { public function getAutoloaderConfig() { return array( 'Zend\Loader