I have an application that works correctly when accessed from a browser, I can query PostgreSQL without any problems but when I try to load it via the console I get the error:
Zend\Db\Adapter\Exception\RuntimeException
Connect Error: could not find driver
The routing, controller and action load correctly as long as I don't try to query the database.
Is there anything I'm missing, maybe something else I need to set when trying to query the DB from the console?
From the console I run it via php /web/public/index.php action which works until I add the DB calls.
//UPDATE
My global.php looks like:
'db' => array(
'driver' => 'Pdo',
'dsn' => 'pgsql:dbname=myDB;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
for brevity;
After discussion on chat, turns out server was configured to handle http and console requests over different PHP binary's. Changing the php path solved the problem.
Related
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.
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
I am having trouble getting Zend to store my session in MySQL table. I have followed the Zend Framework guide step by step, and am not sure if is where am putting the code in my bootstrap file, but once the code snippet is in place and I load my site Apache just crashes. Literally crashes. My logs don't say anyhing.
Here is my code:
$db = Zend_Db::factory( 'Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'root',
'password' => '*****',
'dbname' => 'drecords'
));
Zend_Db_Table_Abstract::setDefaultAdapter( $db );
$config = array(
'name' => 'sessions',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
Zend_Session::setSaveHandler( new Zend_Session_SaveHandler_DbTable( $config ) );
//start your session!
Zend_Session::start();
I am running this code right after at the end of my Bootstrap file.
My question is what am I doing wrong if am following Zends documentation? Is there something I need to know like an extra configuration option in my MySQL or PHP.ini that am not aware of?
Did you create the table in MySQL?
your user have insert/update/delete privileges on the table
do your php setups output errors, what environment are your running production/development
I think the code should probably output some error but if your disabled the output of those you cannot see them.
I use the module user
http://yiiframework.com/extension/yii-user/
then open localhost/testdrive and get an error - trying to get property of non-object
on line - array('url'=>Yii::app()->getModule('user')->loginUrl,
did everything according to instructions from the link
Maybe you should add 'class' parameter to 'user' to configuration in main.php, ie:
'components'=>array(
'user' => array(
'class' => 'application.components.WebUser',
'allowAutoLogin' => true,
'loginUrl' => array('/ua/user/login'),
)...
I figured out why this was happening to me, too. I had put the block at the end of main.php. If you put it at the beginning, the problem goes away.