zend-framework2

Zend Framework 2 tutorial: Module (Application) could not be initialized

风流意气都作罢 提交于 2019-12-17 18:54:17
问题 I am following the official Zend Framework 2 tutorial for version 2.1. In the Unit Testing section, where I am supposed to run phpunit in module/Application/test I am running into the following problem: user@xubuntu1210:~/Desktop/zf2-tutorial/module/Application/test$ phpunit PHPUnit 3.7.13 by Sebastian Bergmann. Configuration read from /home/user/Desktop/zf2-tutorial/module/Application/test/phpunit.xml.dist E Time: 0 seconds, Memory: 4.00Mb There was 1 error: 1) ApplicationTest\Controller

zf2 Creation of simple service and access it through viewhelper

青春壹個敷衍的年華 提交于 2019-12-17 17:58:26
问题 I am trying to create a simple service in zf2 which I can access using in viewhelper Step1. I have craeted a class in src/Application/Service/Service1.php as follow namespace Application\Service; use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorInterface; class Service1 implements ServiceLocatorAwareInterface { public function __construct() { } public function setServiceLocator(ServiceLocatorInterface $serviceLocator) { } public function

Zend Framework 2 - Global check for authentication with ZFCUser

人盡茶涼 提交于 2019-12-17 15:46:31
问题 I installed ZFCUser successfully. Now I wonder if there is a way to globally check for authentication. As outlined in the wiki there are several ways to check for auth. They all work but do I have to put the check-if-clause really in every single action? All my sites should be only accessable when beeing logged in and if not, you should be rerouted to the login page. Does anybody know if there's a central place where I can put this logic? 回答1: To be honest, I don't think it is a good idea to

TableGateway with multiple FROM tables

南楼画角 提交于 2019-12-17 09:45:49
问题 I would like to do a simple INNER JOIN between two tables in Zend2. Concretely, I would like to do this in Zend2: SELECT * FROM foo, bar WHERE foo.foreign_id = bar.id; I have a FooTable : class FooTable { protected $tableGateway; public function __construct(TableGateway $tableGateway) { $this->tableGateway = $tableGateway; } public function get($id) { $rowset = $this->tableGateway->select(function (Select $select) { $select->from('foo'); }); } } The $select->from('foo'); returns an error: ==>

ZF2 - Get controller name into layout/views

删除回忆录丶 提交于 2019-12-17 07:26:49
问题 I know with ZF1 you would retrieve the module/controller name using custom View Helpers that would get the singleton frontController object and get the name there. Using ZF2 as they've abolished alot of the singleton nature of the framework and introduced DI where I've specified aliases for all of my controllers within this module... I can imagine I would get it through accessing the DI or perhaps injecting the current name into the layout. Anyone got any idea how you would do it. I guess

ZF3/2 - how to catch an exception thrown within EVENT_DISPATCH listener?

…衆ロ難τιáo~ 提交于 2019-12-14 04:25:33
问题 Is there any way I can serve an exception thrown within EVENT_DISPATCH listener? class Module { public function onBootstrap(EventInterface $event) { $application = $event->getTarget(); $eventManager = $application->getEventManager(); $eventManager->attach(MvcEvent::EVENT_DISPATCH, function(MvcEvent $event) { throw new ForbiddenException("403 - Fobidden"); }); } } I have a common way of serving ForbiddenException like setting 403, returning JSON, etc... All of the logic is attached to MvcEvent

ZF2 - Need to display specific error message on specific condition failure

别说谁变了你拦得住时间么 提交于 2019-12-14 03:52:01
问题 I am using ZF2 form validation.I have to validate two fields USERNAME and PASSWORD. everything is working fine but I am getting message like Please enter username. Username can not be less than 3 characters. Please enter password. Password can not be less than 6 characters. If user is not entering any value then only this message should display Please enter username. Please enter password. I don't want do display all the error messages on a field on failure. Thanks in advance. 回答1: I got the

What is the best way to keep data between actions in zend framework 2?

廉价感情. 提交于 2019-12-14 03:15:52
问题 I have a form and it is subdivided in multiple steps, and i would like to know what is the best way to keep the data. I'm using php with zend framework 2 回答1: Store the data in a session. This would be true in any application. 来源: https://stackoverflow.com/questions/18406480/what-is-the-best-way-to-keep-data-between-actions-in-zend-framework-2

form not binding post values to entity

大憨熊 提交于 2019-12-14 01:36:05
问题 I have a doctrine entity, a form and 2 fieldsets. When i populate the entity with values the values get hydrated into the form as expected. When i try to create a entity from form data it stays empty.. i must be forgetting something but just cant find it, i have several other forms without fieldsets and they work as expected. any ideas? posted my code below Entity: class User { /** * @var int * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /**

Apache Virtual Host Setup on Centos for Zend Framework 3

风流意气都作罢 提交于 2019-12-13 20:39:50
问题 I am newbie to zf3 and have extracted the ZF3 Skeleton Application from GitHub into location /var/www/html/zf2-tutorial and had installed successfully to get the zf3 home page from URL https://xxx.xxx.xx.xx/zf2-tutorial/public While going through the tutorial i found i have to set up a virtual host to access the site like zf2-tutorial.localhost so i followed the steps and making a zf2-tutorial.conf file under /etc/httpd/conf.d folder . zf2-tutorial.conf <VirtualHost *:80> ServerName https:/