Salut !
Voici mon problème : je me suis mis depuis peu au Zend Framework et j'essaie de bidouiller, de tester... J'ai suivi un tuto... nikel tout fonctionne ajout, modif, sup... Mais je voulais tester en mettant directement une requête SQL et traiter le résultat pour voir mais j'ai que dalle car je crois que mon tableau de retour n'est pas considéré comme tel, voici ma conf :
index.php
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
21
22
23
24
25
26
27
28
29
30
31
32
33 <?php error_reporting(E_ALL|E_STRICT); ini_set('display_errors', 1); date_default_timezone_set('Europe/Paris'); // mise en place des répertoires et chargement des classes set_include_path('.' . PATH_SEPARATOR . './library' . PATH_SEPARATOR . './application/models/' . PATH_SEPARATOR . get_include_path()); include "Zend/Loader.php"; Zend_Loader::registerAutoload(); // Chargement de la configuration $config = new Zend_Config_Ini('./application/config.ini', 'general'); $registry = Zend_Registry::getInstance(); $registry->set('config', $config); // Mise en place de la BDD $db = Zend_Db::factory($config->db); Zend_Registry::set('dbAdapter', $db); Zend_Db_Table::setDefaultAdapter('dbAdapter'); // setup controller $frontController = Zend_Controller_Front::getInstance(); $frontController->throwExceptions(true); $frontController->setControllerDirectory('./application/controllers'); Zend_Layout::startMvc(array('layoutPath'=>'./application/layouts')); // run! $frontController->dispatch();
Albums.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 class IndexController extends Zend_Controller_Action { function indexAction() { $this->view->title = "Mes albums"; $album = new Albums(); $result = $album->afficher(); $this->view->albums = $result; } }
index.phtml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?php class Albums extends Zend_Db_Table { protected $_name = 'albums'; function afficher() { $select = $this->select() ->from('albums', array('id', 'artist', 'title')); $result = $this ->fetchRow($select); } }
Voilà et j'obtiens le warning suivant :
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 <p><a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'ajouter')); ?>">Ajouter un nouvel album</a></p> <table> <tr> <th>Title</th> <th>Artist</th> <th> </th> </tr> <?php foreach($this->albums as $album) : ?> <tr> <td><?php echo $this->escape($album->title);?></td> <td><?php echo $this->escape($album->artist);?></td> <td> <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'modifier', 'id'=>$album->id));?>">Modifier</a> <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'supprimer', 'id'=>$album->id));?>">Supprimer</a> </td> </tr> <?php endforeach; ?> </table>
Et mon tableau vide...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Warning: Invalid argument supplied for foreach() in /var/www/zf-tutorial/application/views/scripts/index/index.phtml on line 10
Quelqu'un peut m'aider svp ? J'ai googlisé pendant un bon moment et il n'en est ressorti que des échecs...
Partager