zend-framework2

Autoloading Zend Framework 2 packages with the StandardAutoloader

心不动则不痛 提交于 2019-12-23 05:36:08
问题 I was previously using a downloaded version of Zend Framework 2 and was basically able to do something like this: // Set include paths (add Zend to the path) set_include_path(get_include_path() . PATH_SEPARATOR . $__CONFIG['zendPath']); // Setup the Zend Autoloader require_once('library\Zend\Loader\StandardAutoloader.php'); $autoLoader = new StandardAutoloader(array( 'namespaces' => array( 'Zend' => $__CONFIG['zendPath'] . '/library/Zend' ) )); This works because all Zend packages are inside

How to forward to another route at Module.php without redirect?

主宰稳场 提交于 2019-12-23 05:19:21
问题 I wish to show login form at page being accessed without url redirection. Is it possible to forward route at Module.php, i.e. if client accesses /stations/ forward it to "user/login" route? Without external redirect, I just want to see login form at private pages. public function onBootstrap(MvcEvent $e){ # .... other $eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'checkAuth'), -100); } public function checkAuth(MvcEvent $e){ # ... get auth service if (!$auth->hasIdentity()) { #

ZF2 sanitize variables for DB queries

被刻印的时光 ゝ 提交于 2019-12-23 04:43:48
问题 In making database queries in Zend Framework 2, how should I be sanitizing user submitted values? For example, $id in the following SQL $this->tableGateway->adapter->query( "UPDATE comments SET spam_votes = spam_votes + 1 WHERE comment_id = '$id'", \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE ); 回答1: You can pass parameters when you execute.. $statement = $this->getAdapter()->query("Select * from test WHERE id = ?"); $result = $statement->execute(array(99)); $resultSet = new ResultSet;

Zend Framework 2 dispatch event doesn't run before action

自闭症网瘾萝莉.ら 提交于 2019-12-23 04:02:42
问题 I need some help. I want to run a method in Zend Framework 2 before the controller's action runs. I putted my method in Module.php's onBootstrap, but it doesn't run before action initated. In Module.php: public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $app = $e->getApplication(); $em = $app->getEventManager(); $em->attach(MvcEvent::EVENT_DISPATCH,

Access ViewModel variables on dispatch event

你。 提交于 2019-12-23 02:38:09
问题 This is a ZF2 question. I'm trying to change my template, depending on a variable setted on my controller (since is there that im going to decide which template use). In my module onBooststrap i have: $this->eventManager->attach('dispatch', function($e) { if (0 === strpos($e->getRouteMatch()->getParam('controller'), __NAMESPACE__, 0)) { $e->getViewModel()->setTemplate('layout'); } }, -100); and in my controller: class IndexController extends AbstractActionController { public function

How to do ItemLookup with Zend Service Amazon?

醉酒当歌 提交于 2019-12-23 01:18:27
问题 I would appreciate if anyone could guide me on the correct way on doing an ItemLookup by ISBN using the Zend Amazon Service module (with Zend 2.0). Here is my attempt: $query = new ZendService\Amazon\Query($appId, 'UK', $secretKey); $query->Category('Books')->IdType('ISBN')->ItemID('978-0321784070')->AssociateTag($tag); $result = $query->ItemLookup(); But I get the following errors: Missing argument 1 for ZendService\Amazon\Amazon::itemLookup(), called in D:\wamp\www\site\controllers\dev.php

How can I replace the PhpRenderer in a ZF2 application

核能气质少年 提交于 2019-12-22 18:11:42
问题 I have extended the PhpRenderer class in my ZF2 application like this: namespace MyLib\View\Renderer; class PhpRenderer extends \Zend\View\Renderer\PhpRenderer { } I don't want to add a new rendering strategy, I just extend the PhpRenderer to add some @method phpdoc for my viewhelpers. How can I replace the standard PhpRenderer with my extended PhpRenderer so it will be used to render my viewscripts? 回答1: The php renderer is a service inside the service manager. You can override this service

ZF2 Curl not sending post values

折月煮酒 提交于 2019-12-22 16:30:56
问题 Im trying to use the native Zend Framework 2 http\curl libraries, I can get it to send the request to the remote application I am just unable to get it to POST values to it. Here is my code that shows 2 examples, the first one is using native PHP curl and it works fine, the second one is using the ZF2 http\curl libraries and it does not pass any of the POST parameters. Example 1 (Native PHP libraries) $url = $postUrl . "" . $postUri; $postString = "username={$username}&password={$password}";

ZF2 Get params in factory

送分小仙女□ 提交于 2019-12-22 12:27:14
问题 I have a dynamic category navigation. In the navigation factory I want to get a param from the route. How can I do this? In my view <?php echo $this->navigation('CategoryNavigation')->menu()->setUlClass('list-group'); ?> In my module.php: public function getServiceConfig() { return array( 'factories' => array( 'CategoryNavigation' => 'Application\Navigation\CategoryNavigation', ) ); } This is my navigation factory. I need to get the slug from the route where {{ store slug }} (2x) is defined.

Zf3 controller not able to access the model class table located in another module

寵の児 提交于 2019-12-22 12:12:12
问题 I am new to Zend Framework. Is there a way to access the model class table which is located in another module from my active controller? As its bye bye service locator in ZF3 i am not able to access the model class table located in other modules. Previously in ZF2 controller private configTable; public function getConfigTable() { if (!$this->configTable) { $sm = $this->getServiceLocator(); $this->configTable = $sm->get('Config\Model\ConfigTable'); // <-- HERE! } return $this->configTable; }