Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Bonsoir,
Je commence une autoformation à ZF avec le guide, mais me voilà déjà confronté à la dure réalité de l'erreur. En effet sur cette étape du guide (http://framework.zend.com/manual/en/lea … model.html) sur les bases de données. Mais je bloque en exécutant le script suivant :
<?php defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); set_include_path(implode(PATH_SEPARATOR, array( APPLICATION_PATH . '/../library', get_include_path(), ))); require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); $getopt = new Zend_Console_Getopt(array( 'withdata|w' => 'Load database with sample data', 'env|e-s' => 'Application environment for which to create database (defaults to development)', 'help|h' => 'Help -- usage message', )); try { $getopt->parse(); } catch (Zend_Console_Getopt_Exception $e) { echo $e->getUsageMessage(); return false; } if ($getopt->getOption('h')) { echo $getopt->getUsageMessage(); return true; } $withData = $getopt->getOption('w'); $env = $getopt->getOption('e'); defined('APPLICATION_ENV') || define('APPLICATION_ENV', (null === $env) ? 'development' : $env); $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $bootstrap = $application->getBootstrap(); $bootstrap->bootstrap('db'); $dbAdapter = $bootstrap->getResource('db'); if ('testing' != APPLICATION_ENV) { echo 'Writing Database Guestbook in (control-c to cancel): ' . PHP_EOL; for ($x = 5; $x > 0; $x--) { echo $x . "\r"; sleep(1); } } $options = $bootstrap->getOption('resources'); $dbFile = $options['db']['params']['dbname']; if (file_exists($dbFile)) { unlink($dbFile); } try { $schemaSql = file_get_contents(dirname(__FILE__) . '/schema.mysql.sql'); $dbAdapter->getConnection()->exec($schemaSql); chmod($dbFile, 0666); if ('testing' != APPLICATION_ENV) { echo PHP_EOL; echo 'Database Created'; echo PHP_EOL; } if ($withData) { $dataSql = file_get_contents(dirname(__FILE__) . '/data.mysql.sql'); $dbAdapter->getConnection()->exec($dataSql); if ('testing' != APPLICATION_ENV) { echo 'Data Loaded.'; echo PHP_EOL; } } } catch (Exception $e) { echo 'AN ERROR HAS OCCURED:' . PHP_EOL; echo $e->getMessage() . PHP_EOL; return false; } return true; ?>
en console j'ai l'erreur :
Fatal error: Uncaught exception 'Zend_Config_Exception' with message 'parse_ini_file(/configs/application.ini): failed to open stream: No such file or directory' in /media/www-dev/ZendFrameworkCli/library/Zend/Config/Ini.php:181 Stack trace: #0 /media/www-dev/ZendFrameworkCli/library/Zend/Config/Ini.php(201): Zend_Config_Ini->_parseIniFile('/configs/applic...') #1 /media/www-dev/ZendFrameworkCli/library/Zend/Config/Ini.php(125): Zend_Config_Ini->_loadIniFile('/configs/applic...') #2 /media/www-dev/ZendFrameworkCli/library/Zend/Application.php(383): Zend_Config_Ini->__construct('/configs/applic...', 'development') #3 /media/www-dev/ZendFrameworkCli/library/Zend/Application.php(85): Zend_Application->_loadConfig('/configs/applic...') #4 /media/www-dev/private/zTestIde/application/scripts/load.mysl.php(42): Zend_Application->__construct('development', '/configs/applic...') #5 {main}
J'ai lu que cela pouvait être dû au droit d'accès, mais j'ai tous les droits sur les répertoires donc je ne comprends pas.
J'ajoute que après un ou deux tests j'ai remarqué que la constante APPLICATION_PATH est vide, est ce normale ?
astro
Dernière modification par astro (11-11-2010 22:02:03)
Hors ligne
Je soupçonne que tu as un problème dans ton arborescence :
J'ai l'impression que
realpath(dirname(__FILE__) . '/../application')
te renvoie false, ce qui signifierait que que ton répertoire application n'existe pas.
Tu peux faire un
echo dirname(__FILE__) . '/../application';
et regarder si le répertoire existe bien. S'il n'existe pas, c'est normal que le realpath renvoie false au lieu du répertoire réel.
A+, Philippe
Hors ligne
Merci de votre réponse, malheureusement le problème ne semble pas venir de là, voici le chemin que me retourne la ligne :
/media/www-dev/private/zTestIde/application/scripts/../application
édit: aprés vérification c'est realpath qui renvoie false, donc il ne résout par le chemin retourné car effectivement il est impossible. Il faudrait donc modifier :
realpath(dirname(__FILE__) . '/../application');
en
realpath(dirname(__FILE__) . '/../');
Pour un script pourquoi pas, mais cela ne devrait-il pas marcher sans bidouille ?
astro
Dernière modification par astro (12-11-2010 11:51:32)
Hors ligne
Effectivement il y a un coquille dans la doc.
Bon, j'étais parti pour créer un ticket, mais jira est en rade...
@mikaelkael, il y a donc une coquille dans la doc :
http://framework.zend.com/manual/en/lea … model.html
il faut changer les lignes suivantes dans le code de scripts/load.sqlite.php :
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
par
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(dirname(__FILE__)) . '/../application'));
A+, Philippe
Hors ligne
Merci de votre aide après correction cela marche.
astro
Hors ligne