tablegateway

Zend Framework 2 model foreign keys

旧时模样 提交于 2020-01-03 06:20:06
问题 I am now approaching Zend Framework 2 and I followed the tutorial on creating a simple CRUD application. Everything is fine but now I want to, for instance, add a genre to the album. I added a category table to the database and created a foreign key category_id in the album table which refers to the category.id in the category table. How do I reflect this situation on my model using TableGateway ? 回答1: I hope this will help you and you will get the idea how to accomplish your task: <?php In

Zend Framework 2: How to get ServiceLocator in validation class

雨燕双飞 提交于 2020-01-02 12:20:29
问题 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-

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: ==>

Zend 2 - TableGateway Where Clauses

笑着哭i 提交于 2019-12-12 18:43:06
问题 Hi I am trying to get to grips with Zend 2 and I'm having some problems with where clauses in the table gateway. Below is my table class: //module\Detectos\src\Detectos\Model\OperatingSystemTable.php namespace Detectos\Model; use Zend\Db\TableGateway\TableGateway; class OperatingSystemsTable { public function findOs($userAgent) { $resultSet = $this->tableGateway->select(); foreach ($resultSet as $osRow) { //check if the OS pattern of this row matches the user agent passed in if (preg_match('/

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' =>

LEFT JOIN in ZF2 using TableGateway

做~自己de王妃 提交于 2019-11-30 17:15:33
I have a table: *CREATE TABLE IF NOT EXISTS `blogs_settings` ( `blog_id` int(11) NOT NULL AUTO_INCREMENT, `owner_id` int(11) NOT NULL, `title` varchar(255) NOT NULL, `meta_description` text NOT NULL, `meta_keywords` text NOT NULL, `theme` varchar(25) NOT NULL DEFAULT 'default', `is_active` tinyint(1) NOT NULL DEFAULT '1', `date_created` int(11) NOT NULL, PRIMARY KEY (`blog_id`), KEY `owner_id` (`owner_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;* And the second table: *CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT

LEFT JOIN in ZF2 using TableGateway

自古美人都是妖i 提交于 2019-11-30 16:31:42
问题 I have a table: *CREATE TABLE IF NOT EXISTS `blogs_settings` ( `blog_id` int(11) NOT NULL AUTO_INCREMENT, `owner_id` int(11) NOT NULL, `title` varchar(255) NOT NULL, `meta_description` text NOT NULL, `meta_keywords` text NOT NULL, `theme` varchar(25) NOT NULL DEFAULT 'default', `is_active` tinyint(1) NOT NULL DEFAULT '1', `date_created` int(11) NOT NULL, PRIMARY KEY (`blog_id`), KEY `owner_id` (`owner_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;* And the second table: *CREATE

Zend Framework 2 Paginator + TableGateway

你。 提交于 2019-11-30 00:09:13
问题 How to use the database mapper with the paginator? I'm having a bit trouble understanding how I implement the DbSelect paginator using the code below (right now it's using the Iterator adapter which doesn't work for ResultSets). From what I can tell it's not as straight forward as I would have hoped. DbSelect is expecting a Zend\Db\Sql\Select and an adapter. The adapter is a non issue and can be retrieved with: $this->newsContents()->getAdapter() but I'm having trouble getting a Select object

TableGateway with multiple FROM tables

百般思念 提交于 2019-11-27 08:47:29
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: ==> Since this object was created with a table and/or schema in the constructor, it is read only. So, I