Bonjour,
Voilà, j'aimerais mettre un pager pour les news sur ma page index.
Je me base sur le tuto jobeet pour le faire mais je n'arrive pas a grand chose.
Est-ce que vous pourriez jeter un coup d'oeuil ?
actions.class.php
Nouvelle.class.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 public function executeIndex(sfWebRequest $request) { $this->pager = new sfDoctrinePager( 'Nouvelle', sfConfig::get('max_news') ); $this->pager->setQuery(Doctrine_Core::getTable('Nouvelle')->getNouvelles()); $this->pager->setPage($request->getParameter('page', 1)); $this->pager->init(); }
NouvelleTable.class.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 public function getNouvellesQuery() { $q = Doctrine_Query::create() ->from('Nouvelle n'); return Doctrine_Core::getTable('Nouvelle')->addNouvellesQuery($q); }
indexSuccess.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 public function getNouvelles(Doctrine_Query $q = null) { return $this->addNouvellesQuery($q)->execute(); } public function addNouvellesQuery(Doctrine_Query $q = null) { if (is_null($q)) { $q = Doctrine_Query::create() ->from('Nouvelle n'); } $alias = $q->getRootAlias(); $q->addOrderBy($alias . '.created_at DESC'); return $q; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <?php foreach ( $pager->getResults() as $nouvelle): ?> <div id="news_<?php echo $nouvelle->getId() ?>" class="news"> <!-- --> </div> <?php endforeach; ?>
Merci d'avance
edit:
Je me suis rendu compte que j'avais oublié de poster le message d'erreure que j'ai; Le voici:
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 Fatal error: Call to undefined method Doctrine_Collection::offset() in /var/www/sagaDev/lib/vendor/symfony/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php on line 86 Call Stack: 0.0106 329556 1. {main}() /var/www/sagaDev/web/saga_dev.php:0 4.1788 7190760 2. sfContext->dispatch() /var/www/sagaDev/web/saga_dev.php:13 4.1788 7190804 3. sfFrontWebController->dispatch() /var/www/sagaDev/lib/vendor/symfony/util/sfContext.class.php:170 4.1921 7210048 4. sfController->forward() /var/www/sagaDev/lib/vendor/symfony/controller/sfFrontWebController.class.php:48 4.3992 7604148 5. sfFilterChain->execute() /var/www/sagaDev/lib/vendor/symfony/controller/sfController.class.php:233 4.3996 7605276 6. sfRenderingFilter->execute() /var/www/sagaDev/lib/vendor/symfony/filter/sfFilterChain.class.php:53 4.3996 7605276 7. sfFilterChain->execute() /var/www/sagaDev/lib/vendor/symfony/filter/sfRenderingFilter.class.php:33 4.3999 7606364 8. sfGuardRememberMeFilter->execute() /var/www/sagaDev/lib/vendor/symfony/filter/sfFilterChain.class.php:53 4.4000 7606616 9. sfFilterChain->execute() /var/www/sagaDev/plugins/sfDoctrineGuardPlugin/lib/sfGuardRememberMeFilter.class.php:56 4.4003 7607700 10. sfExecutionFilter->execute() /var/www/sagaDev/lib/vendor/symfony/filter/sfFilterChain.class.php:53 4.4004 7608612 11. sfExecutionFilter->handleAction() /var/www/sagaDev/lib/vendor/symfony/filter/sfExecutionFilter.class.php:42 4.4005 7608612 12. sfExecutionFilter->executeAction() /var/www/sagaDev/lib/vendor/symfony/filter/sfExecutionFilter.class.php:78 4.4005 7608656 13. sfActions->execute() /var/www/sagaDev/lib/vendor/symfony/filter/sfExecutionFilter.class.php:92 4.4008 7609848 14. newsActions->executeIndex() /var/www/sagaDev/lib/vendor/symfony/action/sfActions.class.php:60 5.3049 10795840 15. sfDoctrinePager->init() /var/www/sagaDev/apps/saga/modules/news/actions/actions.class.php:21 5.3049 10795928 16. sfDoctrinePager->getCountQuery() /var/www/sagaDev/lib/vendor/symfony/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php:100 Variables in local scope (#16): $query = class Doctrine_Collection { protected $data = array (0 => class Nouvelle { ... }, 1 => class Nouvelle { ... }); protected $_table = class NouvelleTable { protected $_data = array (...); protected $_identifier = 'id'; protected $_identifierType = 1; protected $_conn = class Doctrine_Connection_Mysql { ... }; protected $_identityMap = array (...); protected $_repository = class Doctrine_Table_Repository { ... }; protected $_columns = array (...); protected $_uniques = array (...); protected $_fieldNames = array (...); protected $_columnNames = array (...); protected $columnCount = 6; protected $hasDefaultValues = NULL; protected $_options = array (...); protected $_tree = NULL; protected $_parser = class Doctrine_Relation_Parser { ... }; protected $_templates = array (...); protected $_filters = array (...); protected $_generators = array (...); protected $_generator = NULL; protected $_invokedMethods = array (...); protected $record = class Nouvelle { ... }; protected $attributes = array (...); protected $parent = class Doctrine_Connection_Mysql { ... }; protected $_impl = array (...); protected $_params = array (...); protected $_locator = NULL; protected $_resources = array (...) }; protected $_snapshot = array (0 => class Nouvelle { ... }, 1 => class Nouvelle { ... }); protected $reference = NULL; protected $referenceField = NULL; protected $relation = NULL; protected $keyColumn = NULL; protected $_locator = NULL; protected $_resources = array () }
Partager