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.
Related
I am working in Sugarcrm 7.8 I am trying to create a relationship between contacts and my custom module example myorder but its not showing in type field when I select my custome module in `Related Module'.
I couldnt able to find any doc which explains such situation. How i can make a one-to-one relationship through studio when its not showingup. I really dont like to create through code as it breaks operations while we try to retrive report. If i work through studio its fine.
Any how i tried creating the follwing files to see if it shows any relationship.
src/custom/Extension/application/Ext/TableDictionary/contacts_myorder_1.php
src/custom/metadata/contacts_myorder_1MetaData.php
But it creates a new relationship via code.
Has anyone been able to achieve anything similar?
Community Question: https://community.sugarcrm.com/message/94195-one-to-many-relationship-type-is-not-showing-in-studio
After some deep research found that, In my custom module i should have explained the relationship between the modules.
After creating the follwoing file. I could able to see the relationships.
src/modules/mycustomodule/clients/base/layouts/subpanels/subpanels.php
src/modules/mycustomodule/vardefs.php
Content: subpanels.php
array (
'layout' => 'subpanel',
'label' => 'LBL_MYCUSTOMMODULE_SUBPANEL_CONTACTS',
'context' => array (
'link' => 'mycustommodule_contacts',
),
),
Content: vardefs.php
'mycustommodule_contacts' => array(
'name' => 'mycustommodule_contacts',
'type' => 'link',
'relationship' => 'contacts_mycustommodule',
'module' => 'Contacts',
'bean_name' => 'Contact',
'source' => 'non-db',
'vname' => 'LBL_MYCUSTOMMODULE_CONTACTS_LINK',
),
After Repair & Rebuild. It works as expected. Hope it helps someone.!
I am getting a 404 for controller not found and I am having difficulty debugging it.
Where would I debug in Zend zf2 to see what controller it is actually looking for?
The error is:
A 404 error occurred
Page not found.
The requested controller could not be mapped to an existing controller class.
Controller:
not-found(resolves to invalid controller class or alias: not-found)
No Exception available
So my question is not for you to find my problem but to help m3 find where in ZEND I can put breakpoints - help me learn to debug what ZEND is doing.
Between the service manager and listeners and autoloaders, and factories etc... I find ZEND so complex that I can't figure out where to put a breakpoint and see what is happening - in this case what controller is it trying to open.
"Teach a man to fish, rather than feed the man fish".
Thanks
For that problem i don't think you can use breakpoint. Because it gives error before action starts, it couldn't found the controller.
My solution for that when i face with that problem.
Check controller file if it has the correct name in both file and class definition and namespace.
Check module.config file for routing and controller definition.
If you are not using autoloader, check classmap file.
In one of your routes you are using a controller which is not defined under the 'controllers' key in your module.config.php
For example in this route there is a controller 'Application\Controller\Index':
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
And you have to create a controller entry:
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController'
),
),
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.
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);
I'm developing a web application using Zend Framework 2 which will be made of several modules, and I'd like to put the entity classes in the module to which they belong.
Is it possible to do this using Doctrine2 ORM? By reading the docs, it seems to always expect to have all the entities under at most one namespace, while I'd like to have
Module1\Entity
Module2\Entity
and so on...
How could this be made possible?
Thanks to all!
The first step to doctrine configuration is within your global configuration file to set up the connection. Personally i do this in two files, the first is ./config/autoload/global.php and the second one being ./config/autoload/local.php
This is for one very reason and this is that anything containing local doesn't get posted into my git repositories. So my credentials are safe.
./config/autoload/global.php
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'dbname' => 'dbname'
)
)
)
),
);
./config/autoload/local.php
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'params' => array(
'user' => 'root',
'password' => ''
)
)
)
),
);
The second step would be to create a driver for your entities. This is done on Module Namespace base.
./modules/ModuleNamespace/config/module.config.php
<?php
namespace ModuleNamespace;
return array(
//... some more configuration
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
)
);
What's happening there? Well, we extend the doctrine['driver'] array by adding a new driver. The driver has the namespace of our module. For this we also need to define the namespace in our configuration file. The driver defines that all Entities for this driver are within a certain path.
The next step done is that the orm_defaults driver gets extended by an assignment defining that all ModuleNamespace\Entity classes are loaded from our ModuleNamespace_driver configuration.
And ultimately this is done for each single module. So no matter if you're having a Filemanager\Entity\File or PictureDb\Entity\File classes, both will work and both will get loaded. Modules are - by nature - independant from each other. Though they can have dependencies, or rather work well together, they function on their own. So multiple modules with multiple entities are no problem at all ;)
I hope this makes you understand the topic a little bit. For live working examples i have wrote two blog posts covering the topic.
Installing Doctrine 2 for Zend Framework 2
First Steps with Doctrine 2
These may also help you out a little bit.
If you are using the DoctrineORMModule Proxies will be written to /data/DoctrineORMModule/Proxy. I'm not sure if you have to create the folder manually and adapt privileges.
Attention:
For some reason the ZendSkeletonApplication ships without namespaces set!
ZendSkeletonApplication / module / Application / config / module.config.php
You may get this error if you forget to set the namespace in each module.config.php!
The class ... was not found in the chain configured namespaces ZfcUser\Entity, \Entity, ZfcUserDoctrineORM\Entity