Copy zend project from one pc to another - php

I want to copy my zend project "InspectionSys" from one pc to another. I make the proper configuration of zend framework on the other pc, when I try to open my project through this URL
http://localhost/zendapps/InspectionSys/public/visits/visit/get_visits
this error occurs
Message: Invalid controller specified (zendapps)
Request Parameters:
array (
'controller' => 'zendapps',
'action' => 'InspectionSys',
'public' => 'visits',
'visit' => 'get_visits',
'module' => 'default',
)
the mapping of the array options and the values are totally incorrect, what is the problem?
EDIT
The mapping should be
array (
'module' => 'visits',
'controller' => 'visit',
'action' => 'get_visits',
'public' => 'public'
)

You should set a virtual host on your apache server. This is better than the solution proposed by bububaba .

Set up baseUrl in the front controller; set it to zendapps/InspectionSys/public. You'll find details in the documentation.

Related

Doctrine Resolve_target_entity in config

I found this on the doctrine website page:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/resolve-target-entity-listener.html
A way to let my entity communicate with an interface which then can be configurable. The only problem is that i cant find anywhere how to put it in my array config. I already checked the configuration source but there is nothing in the docs:
https://github.com/doctrine/DoctrineORMModule/blob/master/docs/configuration.md
Hope someone can help
Thanks
You can use it like this:
'doctrine' => array(
'entity_resolver' => array(
'orm_default' => array(
'resolvers' => array(
'MyModule\Entity\FooInterface' => 'OtherModule\Entity\Foo',
),
),
),
We use it e.g. here (as a live example) in Soflomo\Blog.

PHP ZF2 - How to create dynamic urls

I have been tasked to explore the possibilities of creating dynamic urls.
What we try to achieve is serving a domain for the client.
eg. www.example.com/clients/john/
eg. www.example.com/clients/bill/
These urls are not fixed, but have to be made dynamically everytime a Client registers at our site. Our URL's are build of Controllers and Actions. Like www.example.com/controller/action.
How can this be achieved in the PHP Zend Framework 2?
Big thanks in advance!
All you need is the ZF2 Manual:
I suggest to use segment routes
You can define them like:
'client' => array(
'route' => '/clients/:username',
'constraints' => array(
'username' => '[a-zA-Z][a-zA-Z0-9-]+', //accepted value pattern
),
'defaults' => array( //which action to invoke
'controller' => 'Application\Controller\ClientController',
'action' => 'showclient',
),
));
Then you can create an url with url helper like:
$this->url('client', array('username' => 'John'));
And in your controller you will be able to get username param with:
$this->params()->fromRoute('username');

Creating new Module in Zend Studio (Zend Framework 2)

I have been following the tutorial from Zend (http://www.youtube.com/watch?feature=player_embedded&v=EerB9bTvqrY) however when I add a new Module in my project I can not navigate to it, are the instructions in this tutorial incorrect?
Basically when I add a new Module in Zend Studio to my Zend Framework project I can not navigate to it, my new module is called "deals". I navigate to localhost/dealproject/deals and I get error 404. When navigating to localhost/dealproject/ it loads the zend skeleton application page correctly.
Thanks for your help.
module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Deals\Controller\Deals' => 'Deals\Controller\DealsController',
),
),
'router' => array(
'routes' => array(
'deals' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/deals',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'Deals\Controller',
'controller' => 'Deals',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default when developing a module;
// as you solidify the routes for your module, however,
// you may want to remove it and replace it with more
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'Deals' => __DIR__ . '/../view',
),
),
);
Make sure you've enabled the module in ~/config/application.config.php
'modules' => array(
'Application',
'Deals',
),
To me the route configuration looks correct and it should show results. What I noticed is that your base URL (localhost/dealproject/) for the ZF2 application is in a sub directory of the domain's root. As you probably know all the requests are mapped to the index.php of your application (~/public/index.php). This is done by some configuration in your .htaccess file (in the same directory).
In the example URL www.example.com/blog if blog doesn't exists as a folder under www.example.com's root you get a 404 Page not found. However, the .htaccess of ZF2 makes apache call the index.php in the domain's root if no directory is found (this assumes you use the ZendSkeletonApplication).
Now, since your index.php is not in the domain root (localhost/) but in localhost/dealproject/ and your .htaccess is (I assume) in localhost/dealproject/ as well, when you call localhost/dealproject/deals apache is looking for a directory dealproject/deals since in localhost there is no .htaccess to prepare the necessary configuration.
I would advise you to make dealproject folder the root of localhost. This will enable you to call your route like this: localhost/deals and .htaccess and index.php will be processed correctly.
Hope this helps :)
Stoyan

How do I configure Dependency Injection in Zend Framework 2?

DISCLAIMER: I'm a complete noob to Zend.
I'm evaluating Zend Framework 2 at work, and trying to configure it to work with ZfTwig for templating. (See here: https://github.com/mtymek/ZfTwig)
I got through Step 3 of the config ok, but I can't figure out Step 4.
I tried placing the following in application.config, but no good.
Where am I supposed to put this?
return array(
'di' => array(
'instance' => array(
// setup other stuff...
// ...
// setup view script resolvers - very similar to configuration
// from ZendSkeletonApplication
'Zend\View\Resolver\AggregateResolver' => array(
'injections' => array(
'Zend\View\Resolver\TemplateMapResolver',
'ZfTwig\TemplatePathStack',
),
),
'Zend\View\Resolver\TemplateMapResolver' => array(
'parameters' => array(
'map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.twig',
),
),
),
'ZfTwig\TemplatePathStack' => array(
'parameters' => array(
'paths' => array(
'application' => __DIR__ . '/../view',
),
),
),
// Tell TwigRenderer how it should locate .twig files
'ZfTwig\TwigRenderer' => array(
'parameters' => array(
'resolver' => 'Zend\View\Resolver\AggregateResolver',
),
),
),
);
Google is no help... I can't find any documentation on Zend's site or anywhere telling me where this is supposed to go.
Thanks for the help!
The di configuration is from the first betas of Zend Framework 2. Zend\Di is a component still available, but internally (as with many other modules) replaced by Zend\ServiceManager.
Basically, both are able to provide dependency injection. Only for Zend\Di it can do this kind-of automatically and for Zend\ServiceManager there are other options to make dependency injection more explicit.
To give an answer to your question: ZfcTwig is now part of ZF-Commons and https://github.com/ZF-Commons/ZfcTwig is the location you have to search for now. Just for your insights, this file is an example of a factory used by the service manager. For more background of service managers in Zend Framework 2, I have written a blog post two months ago which might be interesting.

Unable to route with module in ZF2

I've created a module, a basic copy of the the albums example given in the ZF2 documentation, however, with the new module, I am not able to access it at all - I'm always given a 404 error. I'm building this on the ZF2 skeleton.
I've got three modules loaded: Application, Frontend and Security.
Both Frontend and Security are duplicates of each other, however, I have thoroughly checked and there is no reference to old code (as I literally copied the module folder and renamed/rewrote references).
The module is also loaded in application.config.php.
Any ideas on what I'm missing?
Module Config:
return array(
'controllers' => array(
'invokables' => array(
'Security\Controller\Security' => 'Security\Controller\SecurityController',
),
),
'router' => array(
'routes' => array(
'security' => array(
'type' => 'segment',
'options' => array(
'route' => '/security[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Security\Controller\Security',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'security' => __DIR__ . '/../view',
),
),
);
I had the same problem while following the skeleton application tutorial (Getting started: A skeleton application). Whenever I would go to the album url in the browser (ZendSkeletonApplication/public/album in my case), I would get a 404 error page but no details on why I got the 404. It wasn't clear to me how I would be able determine why I was getting the 404 when I had double checked everything and was pretty sure I copied and configured the Album module properly. It turned out that I was missing a slash in my route (module.config.php). For example I had 'route' => 'album[/:action][/:id]' instead of 'route' => '/album[/:action][/:id]'.
I was only able to figure it out by intentionally causing errors by misspelling things like making the 'Album\Controller\Albums' instead of 'Album\Controller\Album'in the invokables value, this would cause a stack trace to display which then showed the ZF2 classes that where called on the request. I would continue to misspell, test, and then correct each part of the module.config.php until I was given a clue to what part of the configuration was causing the error.
I'm pretty sure this was not the best way to debug an application's configuration.
There is few things that need to be make sure is:-
You have to add your module in
application.config.php (which you are saying you done it.)
Security\Controller\Security has to be same in default too (which you already has)
One more thing is Your folder structure....
-
Just to doulbe check you have a /MODULE/src/MODULE/Controller/CONTROLLER_FILE_NAME.php
I hope that helps..
I know it is an old post. However another thing to make sure you have in the modules top directory (same directory as the Module.php file) is the "autoload_classmap.php"
file with "<?php return array();?>" inside of it.
A simple tip to know whether your rule has already added correctly to the routes or not, you may check the routes value in the config file inside any working module, as following:
$config = $this->serviceLocator->get('config');
var_dump($config);

Categories