I am trying to add a extra connection to my doctrine configuration. my orm_default connection works perfectly fine, and now I'm trying to add a new module with its own Doctrine configuration (mostly learning purposes, buts its rather annoying that I can't get it to work).
The module is called Frontpage, and all relevant code is in this one, except for username/password details that resides in local.php...
My error is
Zend\ServiceManager\Exception\ServiceNotCreatedException
An exception was raised while creating "doctrine.entitymanager.orm_hosts"; no instance returned
Also further down the stacktrace (the last exception) which I think is relevant, but don't know how to fix...
Zend\Stdlib\Exception\BadMethodCallException
The option "hydration_cache" does not have a matching setHydrationCache setter method which must be defined
Here is my module config (relevant parts) file:
'doctrine' => [
'connection' => [
'orm_hosts' => [
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => [
'host' => '127.0.0.1',
'port' => '3306',
'dbname' => 'hosts',
],
],
],
'entitymanager' => array(
'orm_hosts' => array(
'connection' => 'orm_hosts',
'configuration' => 'orm_hosts'
)
),
'configuration' => array(
'orm_hosts' => array(
'driver' => 'orm_hosts',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\Proxy',
'filters' => array(),
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
//'hydration_cache' => 'array',
)
),
'driver' => array(
'orm_hosts' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\DriverChain',
'drivers' => array(
'Common\Entity' => 'Hosts_Driver'
)
),
'Hosts_Driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/Common/Entity'
)
),
),
'eventmanager' => array(
'orm_hosts' => array()
),
'sql_logger_collector' => array(
'orm_hosts' => array(),
),
'entity_resolver' => array(
'orm_hosts' => array()
),
],
And my Module.php's getServiceConfig():
public function getServiceConfig()
{
return array(
'factories' => array(
'doctrine.connection.orm_hosts' => new Service\DBALConnectionFactory('orm_hosts'),
'doctrine.configuration.orm_hosts' => new Service\ConfigurationFactory('orm_hosts'),
'doctrine.entitymanager.orm_hosts' => new Service\EntityManagerFactory('orm_hosts'),
'doctrine.entity_resolver.orm_hosts' => new Service\EntityResolverFactory('orm_hosts'),
'doctrine.sql_logger_collector.orm_hosts' => new Service\SQLLoggerCollectorFactory('orm_hosts'),
'doctrine.driver.orm_hosts' => new \DoctrineModule\Service\DriverFactory('orm_hosts'),
'doctrine.eventmanager.orm_hosts' => new \DoctrineModule\Service\EventManagerFactory('orm_hosts'),
'DoctrineORMModule\Form\Annotation\AnnotationBuilder\orm_hosts' => function(\Zend\ServiceManager\ServiceLocatorInterface $sl) {
return new \DoctrineORMModule\Form\Annotation\AnnotationBuilder($sl->get('doctrine.entitymanager.orm_hosts'));
},
),
);
}
And here is my getEntityManager() in IndexController that fails
/**
* #return array|EntityManager|object
*/
public function getEntityManager() {
if (NULL === $this->em) {
/** #var \Doctrine\ORM\EntityManager $em */
$em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_hosts');
//$em = $this->getServiceLocator()->get('doctrine')->getManager("orm_hosts");
$this->em = $em;
}
return $this->em;
}
Any help will be gratly appreciated :)
Best regards
Richard
Okay, so I still don't know what is wrong with the above code, but if I remove
'Hydration_cache' => 'array'
In the doctrine configuration from my module config, it actually works! Still, if anyone want's to explain what happens, I would appreciate to know more :)
Related
I am currently developing a custom module.
What I want is to have a nice URL, because right now it looks like this:
domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany
I already added a new page to link to the custom module, the page name is flower-deliveries, but still I have the parameters that I have to "hide".
Instead, of that link above I would like a URL like this:
domain.com/flower-deliveries-1-Hamburg-Germany.html
I tried 2 methods, but none of them worked..
The first one, was to add a hookModuleRoutes in my controller, just like below:
public function hookModuleRoutes($params)
{
return array(
'module-vpages-dpage' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'id_country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
'country' => array('regexp' => '[\w]+', 'param' => 'country')
),
'params' => array(
'fc' => 'module',
'module' => 'vpages',
'controller' => 'dpage'
)
)
);
}
And then, in the controllers install:
$this->registerHook('moduleRoutes');
That didn't worked, so I tried to override the Dispatcher class, by adding a custom module route:
'module-vpages-dpage' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
),
'params' => array(
'fc' => 'module',
'module' => 'vpages',
'controller' => 'dpage'
)
),
When using that custom rule, the link http://domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany was tranformed in http://domain.com/flower-deliveries?module_action=list and it didn't worked and was redirecting me to the first page.
Could some one tell me what am I doing wrong?
I've spent hours of reading how it should be done and it should be just like the ones above..
Thank you!
Revert all edits that you have done :).
Try this way:
For example, this is core module file rootofps/modules/vpages/vpages.php
class VPages extends Module {
public function __construct(){
$this->name = 'vpages';
$this->author = 'you';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->controllers = array('dpage');
parent::__construct();
}
// This is the function in your core module file (not in controller)
public function install(){
return parent::install() && $this->registerHook('moduleRoutes')
}
public function hookModuleRoutes($params){
$my_link = array(
'vpages' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
),
'params' => array(
'fc' => 'module',
'module' => 'vpages'
)
)
);
return $my_link;
}
}
Now the controller rootofps/modules/vpages/controllers/front/dpage.php
class VpagesDpageModuleFrontController extends ModuleFrontController {
public function init(){
parent::init();
$this->setTemplate('dapage.tpl');
}
}
And now the view rootofps/modules/vpages/views/templates/front/dpage.tpl
id_country = {$smarty.get.id_country}<br>
country = {$smarty.get.country}<br>
city={$smarty.get.city}<br>
This 'skeleton' works at 100% :), by the way, notice that if you give an url like this mydomain.com/flower-deliveries?id_country=1&country=italy&city=rome PrestaShop will not transform your url in a clearly url as you want.
But an url like this mydomain.com/flower-deliveries-2-italy-rome.html will be routes properly :)
We're using ZF2 for an web-application and want to test it with phpunit (v4.8.9). Within this application we've got a scheme-route, to be able to switch between http/https-context (Doesnt matter why...). The route looks like this:
'http' => array(
'type' => 'Scheme',
'options' => array(
'scheme' => 'http',
'defaults' => array(
'http' => true
)
),
'child_routes' => array(
'search' => array(
'type' => 'segment',
'options' => array(
'route' => '/search[/:keyword[/:page]]',
'constraints' => array(
'page' => '[1-9]+[0-9]*'
),
'defaults' => array(
'controller' => SearchController::class,
'action' => 'search',
),
),
),
),
),
'https' => array(
'type' => 'Scheme',
'options' => array(
'scheme' => 'https',
'defaults' => array(
'https' => true
)
),
'child_routes' => array(
'search' => array(
'type' => 'segment',
'options' => array(
'route' => '/search[/:keyword[/:page]]',
'constraints' => array(
'page' => '[1-9]+[0-9]*'
),
'defaults' => array(
'controller' => SearchController::class,
'action' => 'search',
),
),
),
),
),
The class of the test looks like this:
class SearchControllerTest extends SynHttpControllerTestCase
{
public function setUp()
{
$this->setApplicationConfig($this->getCurrentBootstrap()->getApplicationConfig());
parent::setUp();
$this->getApplicationServiceLocator()->setAllowOverride(true);
}
public function testSearchActionCanBeAccessed()
{
$this->dispatch('/search');
$this->assertResponseStatusCode(200);
$this->assertControllerName(SearchController::class);
$this->assertControllerClass('SearchController');
$this->assertActionName('search');
$this->assertMatchedRouteName('search');
}
}
FYI:
The "SynHttpControllerTestCase" is an extension from the original AbstractHttpControllerTestCase which comes with Zend-Test. It's modified to get the right bootstrap-file in our tests.
If we're running the tests, this error appears:
Fatal error: Call to a member function getParam() on null in C:\xampp\htdocs\git\xxx\vendor\zendframework\zend-test\src\PHPUnit\Controller\AbstractControllerTestCase.php on line 563
We looked into the AbstractControllerTestCase and this line is throwing the error:
$routeMatch = $this->getApplication()->getMvcEvent()->getRouteMatch();
Because the $routeMatch-Object is empty.
We've some other controllers and tests within our application, they're all fine and not affected from this problem, cause the routes to these controllers arent scheme-routes.
Do you have any ideas how to solve this? In advance: we're not able to use static https-routes in this case.
There is a lot of official documentation on how to write a proper controller test. In your setUp method you need to attach a Router instance to a RouteMatch instance which you attach to a MvcEvent in the controller.
protected function setUp()
{
$serviceManager = Bootstrap::getServiceManager();
$this->controller = new IndexController();
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$config = $serviceManager->get('Config');
$routerConfig = isset($config['router']) ? $config['router'] : array();
$router = HttpRouter::factory($routerConfig);
$this->event->setRouter($router);
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
$this->controller->setServiceLocator($serviceManager);
}
Then you can call dispatch.
UPDATE
Can you not set your route match object like this:
$routeParams = array('controller' => 'search', 'action' => 'search');
$routeMatch = new RouteMatch($routeParams);
$routerConfig = isset($config['router']) ? $config['router'] : array();
$router = HttpRouter::factory($routerConfig);
$event = new MvcEvent();
$event->setRouter($router);
$event->setRouteMatch($routeMatch);
$this->getApplication()->setMvcEvent($event);
I'd like to create multiple loggers where different areas of my app will log to different files. For example, all the classes associated with getting the users data would log to a user.log, all functionality of making purchases going to a purchase.log. I am using the configuration array method for setting up the logger & appenders. In my index.php:
require_once('log4php/Logger.php');
require_once('classB.php');
require_once('classA.php');
Logger::configure(array(
'rootLogger' => array('appenders' => array('default')),
'classALogger' => array('appenders' => array('classAAppender')),
'appenders' => array(
'default' => array(
'class' => 'LoggerAppenderEcho',
'layout' => array(
'class' => 'LoggerLayoutSimple'
)
),'classAAppender' => array(
'class' => 'LoggerAppenderFile',
'additivity' => false,
'layout' => array(
'class' => 'LoggerLayoutSimple'
),
'params' => array(
'file' => 'log/classA.log',
'append' => true
)
)
),
));
$logger = Logger::getLogger("main");
$logger->info('message from index' . '<br>');
$classA = new ClassA();
$classA->test();
Class A is as follows:
class ClassA
{
public function test()
{
$logger = Logger::getLogger("classALogger");
$logger->error('from ClassA');
}
}
I am able to log to the default or root logger but am not able to log to, in this example, classALogger. Any suggestions?
I have some problems with my Yii system. All modules are working fine in the system, but there is an error with the activity module. It returns the following error:
2013/10/22 10:21:17 [error] [exception.CHttpException.404] exception 'CHttpException' with message '"activity/default/list" isteği çözümlenemedi.' in /var/www/yii/framework/web/CWebApplication.php:286
Stack trace:
#0 /var/www/yii/framework/web/CWebApplication.php(141): CWebApplication->runController('activity/defaul...')
#1 /var/www/yii/framework/base/CApplication.php(180): CWebApplication->processRequest()
#2 /var/www/hello/index.php(13): CApplication->run()
#3 {main}
REQUEST_URI=/etkinlikler/liste
Here are my main and defaultController files for activity module.
main.php
<?php
date_default_timezone_set('Asia/Istanbul');
return array(
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'name' => 'Kendim Panel',
'language' => 'tr',
'preload' => array('log'),
'import' => array(
'application.models.*',
'application.modules.*',
'application.components.*',
'application.helpers.*'
),
'modules' => array(
'gii' => array(
'class' => 'system.gii.GiiModule',
'password' => '121212',
'ipFilters' => array('127.0.0.1, 192.168.1.27', '::1'),
),
'wlapi' => array(),
'panel' => array(),
'ileti' => array(),
'anket' => array(),
'hastag' => array(),
'category' => array(),
'product' => array(),
'menu' => array(),
'siparis' => array(),
'kisisel' => array(),
'istatistik' => array()
),
'components' => array(
'CString' => array('class'=>'CString'),
'myFunc' => array('class'=>'myFunc'),
'user' => array(
'allowAutoLogin' => true,
),
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=kendim_db',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
)
, 'urlManager' =>array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'/' => 'panel/default',
'wl-api' => 'wlapi',
'etkinlikler' => 'activity',
'etkinlikler/ekle' => 'activity/default/create',
'etkinlikler/duzenle' => 'activity/default/update',
'etkinlikler/duzenle/id/<id:\d+>' => 'activity/default/update',
'etkinlikler/sil' => 'activity/default/delete',
'etkinlikler/sil/id/<id:\d+>' => 'activity/default/delete',
'etkinlikler/liste' => 'activity/default/list',
'kategoriler' => 'category',
'kategoriler/ekle' => 'category/default/create',
'kategoriler/duzenle' => 'cateogry/default/update',
'kategoriler/duzenle/id/<id:\d+>' => 'category/default/update',
'kategoriler/sil' => 'category/default/delete',
'kategoriler/sil/id/<id:\d+>' => 'category/default/delete',
'kategoriler/liste' => 'category/default/list',
'urunler' => 'product',
'urunler/ekle' => 'product/default/create',
'urunler/duzenle' => 'product/default/update',
'urunler/duzenle/id/<id:\d+>' => 'product/default/update',
'urunler/sil' => 'product/default/delete',
'urunler/sil/id/<id:\d+>' => 'product/default/delete',
'urunler/liste' => 'product/default/list',
),
),
'errorHandler' => array(
'errorAction' => 'panel/default/error',
),
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'CFileLogRoute',
'levels' => 'error, warning',
),
),
),
'image'=>array(
'class'=>'application.extensions.image.CImageComponent',
//GD or ImageMagick
'driver'=>'GD',
'params'=>array('directory'=>'/opt/local/bin',
'product'=>array(
'size'=>array(
'detail'=>array(
'width' => 418,
'height' => 314
),
'thumbnail'=>array(
'width' => 90,
'height' => 68
),
'org'=>array(
'width' => 800,
'height' => 600
),
),
),
),
),
),
);
?>
DefaultController.php
<?php
class DefaultController extends ActivityController
{
public $layout = 'activity';
private $actionStatus;
private $defaultDetailImageWidth;
private $defaultDetailImageHeight;
private $defaultListImageWidth;
private $defaultListImageHeight;
private $defaultOrgImageWidth;
private $defaultOrgImageHeight;
public function actionCreate()
{
$this->pageTitle = "Etkinlik Yönetimi > Etkinlik Ekleme";
$this->render("create", array('model'=>$newActivityModel, 'actionStatus'=>$this->actionStatus, 'categoryGridList'=>$categoryGridList));
}
public function actionList()
{
$this->pageTitle = "Etkinlik Yönetimi > Etkinlik Listeleme";
$this->render("list");
}
public function actionDelete()
{
$this->pageTitle = "Ürün Yönetimi > Ürün Silme";
$this->render("delete", array('actionStatus' => $this->actionStatus));
}
public function actionUpdate()
{
$this->pageTitle = "Ürün Yönetimi > Ürün Güncelleme";
$this->render("update", array('model'=>$product, 'actionStatus' => $this->actionStatus, 'categoryList' => $categoryList));
}
public function actionIndex()
{
$this->render("index");
}
public function actionError()
{
$this->render("error");
}
}
?>
ActivityController.php
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class ActivityController extends CController {
/**
* #var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout = '/layouts/column1';
/**
* #var array context menu items. This property will be assigned to {#link CMenu::items}.
*/
public $constants = array();
public $menu = array(
array('label'=>'Etkinlik Ekle', 'url'=>'/etkinlikler/ekle'),
array('label'=>'Etkinlik Liste', 'url'=>'/etkinlikler/liste'),
);
/**
* #var array the breadcrumbs of the current page. The value of this property will
* be assigned to {#link CBreadcrumbs::links}. Please refer to {#link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs = array();
}
I've set permissions for all files to 777 and I still get the same error.
Also I checked that system is not able to go to controllers. I get the error in main.php
What is the problem?
Ok I found the problem. I haven't defined the activity module in main.php After adding
'activity' => array();
the problem was solved.
Change
array('label'=>'Etkinlik Ekle', 'url'=>'/etkinlikler/ekle'),
array('label'=>'Etkinlik Liste', 'url'=>'/etkinlikler/liste'),
to
array('label' => 'Etkinlik Ekle', 'url' => array('activity/default/create')),
array('label' => 'Etkinlik Liste', 'url' => array('activity/default/list)),
I've seen the same error posted often here and have read through and made changes based on the previous questions and answers, to no avail.
I have installed Doctrine's Mongo ODM with Zend Framework via Composer and completed the installation as described here
https://github.com/doctrine/DoctrineMongoODMModule
I have modified my /config/autoload/module.doctrine-mongo-odm.local.php file beyond the recommendations of the above documentation in an effort to fix my problem and based on answers to similar questions here, so that it now looks as follows
<?php
return array(
'doctrine' => array(
'connection' => array(
'odm_default' => array(
'server' => 'removed.mongolab.com',
'port' => '43957',
'user' => 'removed',
'password' => 'removed',
'dbname' => 'richard',
'options' => array()
),
),
'configuration' => array(
'odm_default' => array(
'metadata_cache' => 'array',
'driver' => 'odm_default',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineMongoODMModule/Proxy',
'proxy_namespace' => 'DoctrineMongoODMModule\Proxy',
'generate_hydrators' => true,
'hydrator_dir' => 'data/DoctrineMongoODMModule/Hydrator',
'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',
'default_db' => 'richard',
'filters' => array(),
'logger' => null
)
),
'odm_default' => array(
'drivers' => array(
'Application\Document' => 'odm_driver'
)
),
'odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
'module/Application/src/Application/Document'
),
),
'documentmanager' => array(
'odm_default' => array(
'connection' => 'odm_default',
'configuration' => 'odm_default',
'eventmanager' => 'odm_default'
)
),
'eventmanager' => array(
'odm_default' => array(
'subscribers' => array()
)
),
),
);
I have a file /module/Application/src/Application/Document/User.php as follows
<?php
namespace Application\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations;
class User {
/** #ODM\Id */
private $id;
/** #ODM\Field(type="bin_data_timestamp") */
private $timestamp;
/** #ODM\Field(type="string") */
private $username;
/** #ODM\Field(type="bin_data_md5") */
private $password;
/** #ODM\Field(type="bin_data_uuid") */
private $salt;
/** #ODM\Field(type="string") */
private $realName;
/** #ODM\Field(type="string") */
private $email;
public function getId() {
return $this->id;
}
// ...
public function setId($id) {
$this->id = $id;
}
// ...
}
In my controller, I'm using the following code.
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$user = new User;
$user->setUsername("test");
$dm->persist($user);
$dm->flush();
However, I'm getting the infamous error
The class 'Application\Document\User' was not found in the chain configured namespaces
Any assistance would be greatly appreciated.
My configuration had become a bit confused, as it turns out. I was able to correct the issue with the following configuration code.
'driver' => array(
'odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../../module/Application/src/Application/Document')
),
'odm_default' => array(
'drivers' => array(
'Application\Document' => 'odm_driver'
)
),
),
NB: The included code for Application\Document\User also produces errors, corrected with the following code.
namespace Application\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/** #ODM\Document */
class User {
// ...
}