Bonjour,
je tente de comprendre et de mettre en place un bootstrap pour une application zend
je pense avoir fait le minimum pour pouvoir démarrer, mais le problème c'est que je n'arrive pas créer mes class modèles, celles qui héritent de Zend_Db_Table
je vous montre le code pour être plus claire
fichier testzend/public/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 <?php // Inclusion de la classe Zend_Loader require_once 'Zend/Loader/Autoloader.php'; set_include_path('.' . PATH_SEPARATOR . 'C:\wamp\www\testzend\application\models' . PATH_SEPARATOR . get_include_path()); $loader = Zend_Loader_Autoloader::getInstance(); Zend_Controller_Front::run('../application/controllers'); $db = new Zend_Db_Adapter_Pdo_Mysql(array( 'host ' => '127.0.0.1', 'username' => 'root', 'password' => '', 'dbname' => 'zendfacile' )); $config = new Zend_Config_Ini('../application/config.ini','dev'); $db = Zend_Db::factory($config->database); Zend_Db_Table::setDefaultAdapter($db);
fichier testzend/application/controllers/IndexController.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 <?php class IndexController extends Zend_Controller_Action { public function indexAction() { } function afficheramisAction() { require_once 'Ami.php'; $this->view->title = "Liste de mes amis"; $amis = new Ami(); $this->view->amis = $amis->fetchAll(); } }
fichier testzend/application/models/Ami.php
la vue
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 <?php class Ami extends Zend_Db_Table { protected $_name = 'ami'; protected $_primary = 'id'; protected $_db; private static $last_insert_id; private static $name_file; public function insertRow($formulaire) { $data = array ( 'nom'=> $formulaire->getValue('nom'), 'prenom'=>$formulaire->getValue('prenom'), 'email'=>$formulaire->getValue('email'), 'idType'=>$formulaire->getValue('idType') ); self::$name_file = $formulaire->getValue('file'); //$this->insert($data), en plus d'ajouter des données, renvoie le dernier id incrémenté self::$last_insert_id = $this->insert($data); } public function updateRow($formulaire) { $id = (int)$formulaire->getValue('id'); $data = array ( 'nom'=>$formulaire->getValue('nom'), 'prenom'=>$formulaire->getValue('prenom'), 'email'=>$formulaire->getValue('email'), 'idType'=>$formulaire->getValue('idType') ); $where=$this->getAdapter()->quoteInto('id = ?', $id); $this->update($data,$where); } public function deleteRow($id) { $where = 'id = '.$id; $this->delete($where); } public function getLastInsertId(){ return self::$last_insert_id; } public function getNameFile() { return self::$name_file; } } ?>
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 <table border="1"> <tr> <th>Nom</th> <th>Prenom</th> <th> </th> <th> </th> </tr> <?php foreach($this->amis as $ami) : ?> <tr> <td><?php echo $ami->nom;?></td> <td><?php echo $ami->prenom;?></td> </tr> <?php endforeach; ?> </table>
quand je tape l'url http://testzend/index/afficheramis
je tombe sur la page d'erreur error.phtml
j'ai même rajouter au fichier php.ini dans la section include_path,
le chemin ;C:\wamp\www\testzend\application\models
quelqu'un pourrait m'éclairer? merci
Partager