zend-framework2

ZF2: Zend Framework 2 Full URL including host name

痞子三分冷 提交于 2019-12-03 06:01:29
问题 In my view I need to draw full URL. Like this: http://hostename.com/default/url When I try to use $this->url('default', array(1,2,3)) I get only /index/get/ . Is there any Zend method to het host name or I have to use $_SERVER['HTTP_HOST'] instead? 回答1: You can use the option force_canonical on the router. All router options go into the third parameter of the url helper: url($route, $params, $options) So you can so something like this: $this->url('myroute', array('id' => 123), array('force

ZF2 How to get last insert id value?

大城市里の小女人 提交于 2019-12-03 05:15:27
I am stuck with getting last insert id with Zend framework 2 and I gave up on this... There are tried combinations: var_dump($this->tableGateway->insert($insert)); var_dump($this->tableGateway->lastInsertValue); var_dump($this->tableGateway->getLastInsertValue()); var_dump($this->tableGateway->getAdapter()->getDriver()->getConnection()->getLastGeneratedValue()); Value is inserting to table, but every line (except first, which gives int "1") returns null. Please don't tell me, that such a big framework does not give possibility to get last insert id value!? Here is what I use: $data = array()//

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

∥☆過路亽.° 提交于 2019-12-03 04:49:25
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 Repositories and still get them like normally from the ObjectManager directly with the getRepository

How to generate entities from database schema using doctrine-orm-module and zf2

丶灬走出姿态 提交于 2019-12-03 04:22:46
问题 I am using "doctrine/doctrine-orm-module": "0.7.0" with ZF2. Once I create Entities I usually run following commands to sync and generate database automatically according to my entities. ./vendor/bin/doctrine-module orm:validate-schema ./vendor/bin/doctrine-module orm:schema-tool:create Is there a way to make this process reverse? I mean, Can I generate entities from existing database in mysql? 回答1: We use a batch script: @ECHO OFF mkdir EXPORT call .\vendor\bin\doctrine-module orm:convert

Zend Framework 2 - Layout and variable

爷,独闯天下 提交于 2019-12-03 04:15:14
问题 i have a layout used by all my views and i need to assign a variable from a controller to this layout , if i use this method on a controller it doesn't work : public function indexAction() { return new ViewModel( array( 'testvar' => 'bla', )); } anyone can help me ? thanks 回答1: Rob Allen has posted a great article about how to access view variables in another view model (e.g.: layout) Basically the following code, placed inside your layout.phtml, will match your needs: <?php $children = $this

zf2 doctrine2 and Zend\\Db\\Adapter\\Adapter using one db connection

放肆的年华 提交于 2019-12-03 04:04:46
I use doctrine2 with ZF2, some of my libraries work with Zend\Db\Adapter\Adapter, others with doctrine2. Now, they connect to database twice. Is it possible to use one db connection in doctrine and standard ZF2 db adapter? The DoctrineORM module accepts a PDO resource or a service name where the instance can be located in the service manager instead of the usual connection params. First step is to create a service factory which retrieves the PDO resource from the Zend\Db\Adapter\Adapter service <?php namespace Application\Db\Service; use Zend\ServiceManager\FactoryInterface; use Zend

multiple tables for Zend Framework 2

前提是你 提交于 2019-12-03 03:58:47
问题 I'm new to Zend Framework 2. I successfully completed the Album tutorial for ZF2. Now I'd like to display only a certain data from multiple tables in the database. I have a simple database setup with tables, for example, person, books, status..etc. It's really not important what the database's supposed to do. What I would like to know is if there's a tutorial that would show me step-by-step guidance to display data from table joins. I have seen snippets of codes showing how to do joins, but I

Zend Framework 2 file download

北城以北 提交于 2019-12-03 03:50:51
I made a form to upload files to the folder ./data/uploads using the Zend\Filter\File\RenameUpload filter. This is working like a charm. My problem now is how do I provide this file to users download it? I think it would be something like: $response->setContent(file_get_contents('./data/uploads/file.png')); But I want to know what is the best way to do this. Thanks to @henrik for response, but several important headers are missing in his answer. Be careful of that. Full headers stack: public function downloadAction() { $file = 'path/to/file'; $response = new \Zend\Http\Response\Stream();

Zend Framework 2 module share variables between controllers onBootstrap

流过昼夜 提交于 2019-12-03 03:46:41
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: $config = $this->getServiceLocator()->get('Config') $dba = new DbAdapter($config['db']); I don't want

ZF2 FileUpload Collection

巧了我就是萌 提交于 2019-12-03 03:14:36
I am unable to get my fileupload collection to work. This is what I've done: https://gist.github.com/manuakasam/1ac71daf7269616f55f0 Basically the $request->getFiles() contains the proper information. So the upload to PHP itself works. But once the InputFilter runs over the data, it all gets lost. Apprently FileRenameUpload does something fishy and I can't figure out what exactly. All I know is my data gets lost... Write permissions are not the problem. I'm testing this currently on my devbox on windows via PHP 5.5 CLI Looks like the problem is the Collection of Elements . In the past only