Si la classe s'appelle My_Spaces, alors le fichier doit-être dans le répertoire /My/Spaces.php et non pas dans models, ce qui est bien le but des namespaces non ?
Version imprimable
Si la classe s'appelle My_Spaces, alors le fichier doit-être dans le répertoire /My/Spaces.php et non pas dans models, ce qui est bien le but des namespaces non ?
Non pas forcement.
Tu attribut un namespace à un répertoire.
Voici un extrait du fichier /Library/Zend/Application/Module/Autoloader.php
Ce sont les namespace par défaut.
Tu vois bien que pour tes models par défaut tu as deux choix:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public function initDefaultResourceTypes() { $basePath = $this->getBasePath(); $this->addResourceTypes(array( 'dbtable' => array( 'namespace' => 'Model_DbTable', 'path' => 'models/DbTable', ), 'form' => array( 'namespace' => 'Form', 'path' => 'forms', ), 'model' => array( 'namespace' => 'Model', 'path' => 'models', ), 'plugin' => array( 'namespace' => 'Plugin', 'path' => 'plugins', ), 'service' => array( 'namespace' => 'Service', 'path' => 'services', ), 'viewhelper' => array( 'namespace' => 'View_Helper', 'path' => 'views/helpers', ), 'viewfilter' => array( 'namespace' => 'View_Filter', 'path' => 'views/filters', ), )); $this->setDefaultResourceType('model'); }
Soit tes models sont sous
/models/MonModel.php
avec MonModel.php
Soit tes models sont dansCode:
1
2
3
4 class Model_MonModel Extends Zend_db_Table_Abstract { //.... }
/models/DbTable/MonModel.php
avec MonModel.php
Code:
1
2
3
4 class Model_DbTable_MonModel Extends Zend_db_Table_Abstract { //.... }
donc dans mon boostrap je fais ceci
cela devrais fonctionner non ?Code:
1
2
3
4
5
6
7
8 $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace(array('My_','OLE_','Spreadsheet_','Ssh_')); //Zend/Application/Module/Autoloader $loader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Model', 'basePath' => APPLICATION_PATH . '/models', ));
voici la réponse
Citation:
Fatal error: Class 'Model_Spaces' not found in /var/www/RdcMonGG1_8/app/controllers/SpacesController.php
Je loupe quelque chose, mais je sais pas quoi !
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 $loader = new Zend_Application_Module_Autoloader // Pourquoi Module_Autoloader ???? Le register namespace chercher dans /library , il faut donc définir une ressource ! Et si tu nomme tes classes avec les conventions de nommage, tu auras peut-être droit à la récursivité de registering :lol: $application = new Zend_Loader_Autoloader_Resource(array( 'basePath' => APPLICATION_PATH . '/models', 'namespace' => 'Model_', 'resourceTypes' => array( 'all'=>array('path'=>'','namespace'=>''), 'tables'=>array('path'=>'Tables','namespace'=>'Table'), 'forms'=>array('path'=>'Forms', 'namespace'=>'Form') ))) // Tes classes se nomme Model_Table_Membre par exemple, et Model_Form_Login pour un formulaire par exemple encore une fois. Si ta classe est directement contenu dans models fais des essais, j'ai jamais essayé
Oui, mais pas avant lundi, bon wk donc ;)
Bon, cela ne fonctionne toujours pas , voici les codes demandés
Index.php
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../app')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/config/application.ini' ); $application->bootstrap() ->run();
Boostrap.php
application.iniCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initLibraryNamespaces() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace(array('My_','OLE_','Spreadsheet_','Ssh_')); } public function _initLang() { Zend_Session::start(); $session = new Zend_Session_Namespace('default'); if (! isset($session->lan)) { $session->lan = 'fr'; } } }
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 [production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.layout.layoutPath = APPLICATION_PATH "/layouts/" [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1
Alors deux choses:
Tu devrais remplacer ça:
Par ces entrées dans ton application.iniCode:
1
2
3
4
5 protected function _initLibraryNamespaces() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace(array('My_','OLE_','Spreadsheet_','Ssh_')); }
Rajoute cette fonction dans ta classe de bootstrap:Code:
1
2
3
4
5 autoloaderNamespaces.0 = "My_" autoloaderNamespaces.1 = "OLE_" autoloaderNamespaces.2 = "Spreadsheet_" autoloaderNamespaces.3 = "Ssh_"
Bien évidement tes models devront respecter le namspace par défautCode:
1
2
3
4
5
6
7
8 protected function _initAutoload() { $moduleLoader = new Zend_Application_Module_Autoloader(array( 'namespace' => '', 'basePath' => APPLICATION_PATH)); return $moduleLoader; }
et être dans le dossier /app/models/Code:
1
2
3
4 class Model_Monmodel extends .... { }
PS: Le truc con, mais si tu développe sous Linux fait attention c'est sensible à la case....
yesssssssssssss, enfin ça marche, ouf......
Merci pour le fameux coup de main. :ccool:
De rien :ccool: