zend-framework2

Access to module config in Zend Framework 2

二次信任 提交于 2019-12-02 17:27:20
How I can get access to my module config from the controller? tomo I am really surprised at how obscure this is, because I had exactly the same problem and could not find a definitive answer. One would think the ZF2 documentation would say something about this. Anyhow, using trial and error, I came across this extremely simple answer: Inside controller functions: $config = $this->getServiceLocator()->get('Config'); Inside Module class functions (the Module.php file): $config = $e->getApplication()->getServiceManager()->get('Config'); whereas $e is an instance of Zend\Mvc\MvcEvent In general,

multiple tables for Zend Framework 2

淺唱寂寞╮ 提交于 2019-12-02 17:20:52
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 haven't found any tutorials on setting up the classes, and how to configure Module.php. In other words

Zend Framework 2 - Layout and variable

对着背影说爱祢 提交于 2019-12-02 16:42:17
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 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->viewModel()->getCurrent()->getChildren(); $child = $children[0]; ?> <!-- some HTML --> <?php echo $this-

ZF2 load service config from module

爱⌒轻易说出口 提交于 2019-12-02 15:19:36
问题 I am still struggling in instantiating a service from a ZF2 module outside of Zend Framework (in a blank .php). I want to achieve: Instantiate + invoke a ZF2 service method from outside ZF by the use of the ServiceManager and possibly DI. What I have now: ( UPDATED 4/10/2013 ) Following up on the comments below I have done more research,particularly: The quick guide http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html RTD (Databases and models) http: //zf2

How to disable render view in zend framework 2?

家住魔仙堡 提交于 2019-12-02 14:57:39
I want to use some ajax, but I don't know how to use function as the same as setNoRender() in zend framework 2 to disable for render view. How to disable rendering view in zend framework 2? Blanchon Vincent To disable your view : public function myactionAction() { // your code here ... return false; } "return false" disables the view and not the layout! why? because the accepted types are: ViewModel array null so "false" disable the view. To disable layout and view, return a response object: public function myactionAction() { // your code here ... return $this->response; } To disable layout:

Move to https://www, when it is www or http:// or without www and http://?

自作多情 提交于 2019-12-02 13:30:40
I am using Zend framework where i have nice looking url controllers. Following .htaccess is working but its making SEO to see us as four links for one page. RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R] I need to do following fix using htaccess: www.stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url stackoverflow.com/nice-looking-url =

Passing forms vs raw input to service layer

半世苍凉 提交于 2019-12-02 13:27:31
Is it better to validate a form and pass its filtered input to the service layer, or to pass the raw input to the service layer, and have the service validate the input (with or without a form instance)? Obviously, if it's the latter, the controller still needs access to the form so that it can be sent to the view for rendering. If so, would you just access the form via the service ($service->getRegistrationForm())? See also: Dependency management in Zend Framework 2 MVC applications Factory classes vs closures in Zend Framework 2 The Form itself should handle the validation, ZF2 has methods

How to remove route on overrided module?

与世无争的帅哥 提交于 2019-12-02 13:17:18
I added zfcUser module to my project via Composer and overrided it in the module ZfcUserOverride . I want trailing slash work, so I added route in overrided module. zfcUserOverride file module.config.php contents below: <?php $config = array( 'view_manager' => array( 'template_path_stack' => array( 'zfcuser' => __DIR__ . '/../view', ), ), 'controllers' => array( 'invokables' => array( 'zfcuser' => 'ZfcUserOverride\Controller\UserController', ), ) ); $config['router']['routes']['zfcuser']['child_routes']['trailing_slash'] = array( 'type' => 'Literal', 'options' => array( 'route' => '/',

Zend Framework 2 Rewrite URL

若如初见. 提交于 2019-12-02 09:47:04
I have a Zend Framework 2 app and I wish to use .htaccess to rewrite some URLs. The .htaccess file is in my public folder. I have verified a simple rewrite rule which rewrites all testurl to test.php RewriteRule ^testurl/?$ test.php [NC] The test.php file is also in the public folder. I placed this rule above the Zend rule to map all URLs to index.php in .htaccess. My question is how do i rewrite this to say the SearchController in the Index Module? I have tried various rewrite rules with different flags such as RewriteRule ^testurl/?$ /index/search [NC] and RewriteRule ^testurl/?$ index

ZF2 load service config from module

本小妞迷上赌 提交于 2019-12-02 09:25:21
I am still struggling in instantiating a service from a ZF2 module outside of Zend Framework (in a blank .php). I want to achieve: Instantiate + invoke a ZF2 service method from outside ZF by the use of the ServiceManager and possibly DI. What I have now: ( UPDATED 4/10/2013 ) Following up on the comments below I have done more research,particularly: The quick guide http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html RTD (Databases and models) http: //zf2.readthedocs.org/en/latest/user-guide/database-and-models.html Modules presentation (Very helpful) http:/