Salut à tous !
J'utilise la nouvelle version de Zend Framework [1.9.6] mais j'ai du mal avec le Zend_Auth !
En effet lors de mon authentification j'ai une erreur du type :
A noter que je suis partie du Quickstart du Zend FrameworkThe supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and column names for validity.
Quelqu'un pour m'aider ?? voici le code des fichiers
Merci
index.php:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php // Set the initial include_path. You may need to change this to ensure that // Zend Framework is in the include_path; additionally, for performance // reasons, it's best to move this to your web server configuration or php.ini // for production. set_include_path(implode(PATH_SEPARATOR, array( realpath(dirname(__FILE__) . '/../library'), get_include_path(), ))); // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap(); $application->run();
bootstrap:
AuthController.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37 <?php /** * Application bootstrap * * @uses Zend_Application_Bootstrap_Bootstrap * @package QuickStart */ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { /** * Bootstrap autoloader for application resources * * @return Zend_Application_Module_Autoloader */ protected function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Default', 'basePath' => dirname(__FILE__), )); return $autoloader; } /** * Bootstrap the view doctype * * @return void */ protected function _initDoctype() { $this->bootstrap('view'); $view = $this->getResource('view'); $view->doctype('XHTML1_STRICT'); } }
application.ini
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 <?php class AuthController extends Zend_Controller_Action { //Initialisation public function init() { $this->initView(); $this->view->baseUrl = $this->_request->getBaseUrl(); } //Action Index public function indexAction() { $this->_redirect('/'); } //Action Login : Authentification de l'utilisateur public function loginAction() { $this->view->title = "Authentification"; $this->view->message = '...Veuillez vous identifier...'; if ($this->_request->isPost()) { //Collecte des données rentrées par l'utilisateur $filter = new Zend_Filter_StripTags(); $login = $filter->filter($this->_request->getPost('login')); $pwd = $filter->filter($this->_request->getPost('pwd')); if (empty($login)) { $this->view->message = '...Champ utilisateur manquant...'; } else { // setup Zend_Auth adapter for a database table Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable'); //$dbAdapter = Zend_Registry::get('dbAdapter'); $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter()); $authAdapter->setTableName('intervenant'); $authAdapter->setIdentityColumn('login'); $authAdapter->setCredentialColumn('pwd'); $authAdapter->setCredentialTreatment("MD5(?)"); //Utilisation du MD5 pour la vérification du mot de passe //Récupération des entrées pour réaliser l'authentification $authAdapter->setIdentity($login); $authAdapter->setCredential($pwd); //Authentification $auth = Zend_Auth::getInstance(); //$auth = Zend_Registry::get('auth'); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { //Authentification Réussie : on stocke les informations de l'utilisateur sauf le mot de passe ! Redirection page Index $data = $authAdapter->getResultRowObject(null, 'pwd'); $auth->getStorage()->write($data); $this->_redirect('/'); } else { //Authentification Echouée : Affichage du message d'echec $this->view->message = '...Echec Authentification (Utilisateur inconnu/Mot de passe incorrect)...'; } } } $this->render(); } //Action Logout : Déconnexion public function logoutAction() { Zend_Auth::getInstance()->clearIdentity(); $this->_redirect('/'); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43 [production] ; PHP settings we want to initialize phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 ; Make sure the following is on the include_path includePaths.library = APPLICATION_PATH "/../library" ; Indicate the path and classname of the bootstrap bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" ; Bootstrap resources: ; - Front Controller ; - Layout ; - Database resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" resources.view[] = ;resources.db.adapter = "PDO_SQLITE" ;resources.db.params.dbname = APPLICATION_PATH "/../data/db/guestbook.db" resources.db.adapter = PDO_MYSQL resources.db.params.host = localhost resources.db.params.username = root resources.db.params.password = "" resources.db.params.dbname = zend_test [staging : production] ; Were you to have a 'staging' environment, you could customize application ; settings here [testing : production] ; For testing, we want to display errors and use a different database phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.db.params.dbname = zend_test [development : production] ; For development, we want to display errors and use a different database phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.db.params.dbname = zend_test
Partager