Autoload Zend framework to Yii - zend-framework

I tried to include Zend framework to Yii with extension. Problem is this:
Warning: include(EZendAutoloader.php): failed to open stream
index.php:
// change the following paths if necessary
$yii=dirname(__FILE__).'/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
EZendAutoloader::$prefixes = array('Zend');
Yii::import("ext.yiiext.components.zendAutoloader.EZendAutoloader", true);
Yii::registerAutoloader(array("EZendAutoloader", "loadClass"), true);
$app= Yii::createWebApplication($config);
$app->run();
Is ok that EZendAutoloader::$prefixes = array('Zend'); is before the import? I also tried to change the argument of Yii:import with no luck.

Related

sails.js : using dust in sails 0.10.5

I am trying to migrate a project from 0.9.9 to 0.10.5
We were using dust templating engine in our porject instead of the default ejs engine.
Contents of config/views.js file
module.exports.views = {
engine: 'dust',
layout: 'layout'
};
In my controller, I was able to render this view like this
res.view('layout', obj);
However, in sails 0.10.5, when I lift sails, first of all I get this warning
warn: Sails' built-in layout support only works with the `ejs` view engine.
warn: You're using `dust`.
warn: Ignoring `sails.config.views.layout`...
And then when I try to render the view as I was doing earlier, I get following error:
error: Sending 500 ("Server Error") response:
Error: ENOENT, open '/.dust'
{ [Error: ENOENT, open '/.dust'] errno: 34, code: 'ENOENT', path: '/.dust' }
Any idea what is the correct way of doing this in 0.10.5 ?
The layout property does not apply to dust (just ejs). Set layout to false to get the warning to go away. You want to use Dust's built-in support for partials and blocks anyways.
Using res.view('layout', obj); means that you expect a file called views/layout.dust to exist. Prior to 0.10, sails was including the layout property from config/views.js as part of the path.
So my best guess is that your res.view() call is actually being invoked with an empty string as the first parameter, and it wasn't breaking because you were trying to render something called layout. I'd check your invocation to make sure that you're calling res.view() with an instantiated variable.

Zend Framework 1.11.12, Doctrine 2.2.2 integration: Error 500

I'm trying to integrate Doctrine 2 into Zend Framework (I'm new to ZF). I've look everywhere on the net but couldn't find my answer...
I've followed this recent tutorial: http://hectorpinol.com/zend-framework-1-11-and-doctrine-2-2-x-integration/ and I've managed to generate a table using the CLI.
The last step of the tuto is to add a new line in this table, simply using the Index controller. But my website doesn't work anymore (a brutal error 500, no message) because I changed the bootstrap.
if I remove the last lines I added to the _initDoctrine() method, it works again (but without Doctrine of course). Here they are:
// set the proxy dir and set some options
$config->setProxyDir(APPLICATION_PATH . '/models/Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setProxyNamespace('App\Proxies');
// now create the entity manager and use the connection
// settings we defined in our application.ini
$connectionSettings = $this->getOption('doctrine');
$conn = array(
'driver' => $connectionSettings['conn']['driv'],
'user' => $connectionSettings['conn']['user'],
'password' => $connectionSettings['conn']['pass'],
'dbname' => $connectionSettings['conn']['dbname'],
'host' => $connectionSettings['conn']['host']
);
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
// push the entity manager into our registry for later use
$registry = Zend_Registry::getInstance();
$registry->entitymanager = $entityManager;
return $entityManager;
Do you have any idea to unlock the situation? It's frustrating because I know I'm so close to make it work...
UPDATE1: I forgot to mention, in case it helps: I'm using WAMP on Windows. Thanks
UPDATE2: Added the parameters of the create() function.
UPDATE3: Actually it might not be an error 500. Chrome says this but Firefox just displays nothing. No answer from the server.
1) Change the environment to development to see the error message.
2) Use Bisna library instead, will save a lot of time (I don't see a point in integrating Doctrine manually well only educational purposes but you might want to save it for later).

symfony how to translate form error message

Does anyone know how to translate form error messages in Symfony ?
At the moment I write this line in the configure() of the form:
sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N'));
And then I overwrite all error messages with the __() method.
Is there any way for Symfony to translate error messages without calling a helper and overwriting error messages ?
How I do it:
Add to the configure function of the Form to following line:
$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('forms');
Then create a translation file like:
\i18n\forms.nl.xml
(in your application root or the plugin root)
It's also possible to add translations for the default validators (like 'Required.', etc.)

Zend Framework unknown module is interpreted as default module

i wanted to support multilingual structure for my work i used the following lines
$controller=Zend_Controller_Front::getInstance();
$router=$controller->getRouter();
$languageRouter=new Zend_Controller_Router_Route(":lang/:module/:controller/:action", array("lang"=>"en","module"=>"default","controller"=>"index","action"=>"index"),
array("lang"=>"[a-zA-Z]{2}"));
$router->addRoute("default",$languageRouter);
it works fine http://localhost/zend/public/en set the lang param to en and call default module
but the problem is that when i use url like this http://localhost/zend/public/en/anything
where anything isn't module it still show the default module how to prevent that???
after the answer of takeshin i added this function to the bootstarp file and now it works as i want it
protected function _initRoutes()
{
$routeLang=new Zend_Controller_Router_Route(':lang',array('lang'=>'en'),array('lang'=>'[a-z]{2}'));
$front = Zend_Controller_Front::getInstance() /*$this->getResource('frontcontroller')*/;
$router = $front->getRouter();
$routeDefault=new Zend_Controller_Router_Route_Module(array(),$front->getDispatcher(),$front->getRequest());
$routeLangDefault=$routeLang->chain($routeDefault);
$router->addRoute('default',$routeLangDefault);
$router->addRoute('lang',$routeLang);
}
It looks like you have overwritten default module defined in Zend Application by your custom one.
You should chain the routes instead.
The settings you are using means module will 'default' to default , if you didn't it would throw a route not found error - which should throw to appropriate error controller
I'm not sure if I unterstood this correctly, but it looks like it works fine, as it should. If you try to call non existing module, Zend Framework automatically "redirects" to the default module.

zend framework stack trace

Is there a way to make stack trace to display the whole generated SQL statement when there is an error instead just the first few characters of it?
This is what it currently displays
...\Zend\Db\Adapter\Pdo\Abstract.php(220): Zend_Db_Adapter_Abstract->query('UPDATE "diction...', Array)
..and I would like to see the whole update statement before sent to the db to track what is wrong with it.
Thanks for the help.
SWK
If you want to view the complete sql statement you can use Zend_Debug. For example if your sql statement is in the variable $select and you want to view the complete sql statement you can use the following line of code:
Zend_Debug::Dump($select);
exit;
Or if your code is created withe the Zend_Db_Table class you can use:
$select = new Zend_Db_Select(Zend_Registry::get('db'));
$select->from('string');
Zend_Debug::Dump($select->assemble());
exit;
I think the best way to view the sql statement is by using the profiling function on the database connection. This is combination withe the logging function and the firePHP add-on for Firefox is my favorite setup.
If you use the MVC configuration of Zend Framework this is done white this lines of code:
// setup the database connection
$db = Zend_Db::factory(Zend_Registry::get('config')->database->adapter,Zend_Registry::get('config')->database->params);
// create a new profiler
profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
// enable profiling (this is only recommended in development mode, disable this in production mode)
$profiler->setEnabled(true);
// add the profiler to the database object
$db->setProfiler($profiler);
// setup the default adapter to use for database communication
Zend_Db_Table_Abstract::setDefaultAdapter($db);
// register the database object to access it in other parts of the project
Zend_Registry::set('db',$db);
/**
*
* This part is optional
*
* You can use this logger to log debug information to the firephp add-on for Firefox
* This is handy for debugging but must be disabled in production mode
*
*/
// create logger
$logger = new Zend_Log();
// create firebug writer
$firebug_writer = new Zend_Log_Writer_Firebug();
// add writer to logger
$logger->addWriter($firebug_writer);
// register the logger object to access it in other parts of the project
Zend_Registry::set('log',$logger);
The firebug add-on (requirement for firephp) can be found on this website:
Firebug
The FirePHP add-on can be found on this website:
FirePHP
Ivo Trompert
whilst the profiler is V cool - it doesn't help debug when the system throws an exception..
check out this post on giving a more detailed stack trace inc full SQL
ONLY TO BE USED IN DEV ENVIRONMENTS for obvious reasons
http://www.edmondscommerce.co.uk/blog/zend-framework/zend-framework-more-detailed-stack-trace/