Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Salut,
J'utilise zend paginator dans l'action recherche,voilà mon code:
-------------------------------VilleController-----------------------------------------
----------------rechercheAction
public function rechercheAction() { $this->_helper->layout->setLayout('layout_ville'); /*************Récupration des Parametres de la requete****************/ $lang = $this->_getParam('lang'); $registry = new Zend_Registry(); $db=$registry->get('db'); $translate = $registry->get('translator'); $ville= $this->_request->getParam('lieu') ; $categorie= $this->_request->getParam('categorie') ; /*********************************/ $translate->removeCache(); SessionHandler::langCookie($lang, $translate); /**********************Informations ville*****************************/ $req=$db-> select() -> from('ville', array('ville_id','ville_meteo'))->where('ville_nom=?',$ville)->query()->fetch(); $ville_id=$req->ville_id; $ville_meteo=$req->ville_meteo; /***********************Sliders***************************************/ $sliderRows = $db->fetchAll($db ->select()->from(array('s' => 'slider')) ->join(array('v' => 'ville'),'s.ville_id = v.ville_id') ->where('s.ville_id = ?', $ville_id) ); /**********************les menus top et bottom******************************/ $categRows=$db ->fetchAll($db -> select() -> from('categorie', array('categorie_id','categorie_titre','width'))->where('parent_id = ?','0')); $count=count($categRows); /**********************Requête de recherche********************************/ $req1=$db -> select() -> from('categorie', 'categorie_id')->where('categorie_titre = ?',$categorie)->query()->fetch(); if($req1) { $categ_id=$req1->categorie_id; Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); $select=$db->fetchAll($db ->select()->from(array('e' => 'etablissement')) ->where('e.ville_id = ?', $ville_id) ->where('e.categorie_id = ?', $categ_id) ); $paginator = Zend_Paginator::factory($select); $paginator->setCurrentPageNumber($this->_getParam('page',1)); $paginator->setItemCountPerPage(2); /******************Préparation des paramêtres de view********************/ $this->view->translate = $translate; $this->_setParam('lang', $translate->getLocale()); $this->view->paginator = $paginator; $this->view->select=$select; } else { $this->view->translate = $translate; $this->_setParam('lang', $translate->getLocale()); $this->view->erreur="Aucun resultat n est trouve"; } $this->_setParam('ville',$ville); $this->view->ville=$ville; $this->view->ville_id = $ville_id; $this->view->ville_meteo=$ville_meteo; $this->view->sliderRows=$sliderRows; $this->view->categRows=$categRows; $this->view->count=$count; } }
Le resultat s'affiche dans la première page mais quand je clique sur suivant ,l'erreur suivante s'apparait:
An error occurred Application error Exception information: Message: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound Stack trace: #0 C:\wamp\www\MTK_test2\library\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array) #1 C:\wamp\www\MTK_test2\library\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array) #2 C:\wamp\www\MTK_test2\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Select), Array) #3 C:\wamp\www\MTK_test2\library\Zend\Db\Select.php(686): Zend_Db_Adapter_Pdo_Abstract->query(Object(Zend_Db_Select)) #4 C:\wamp\www\MTK_test2\application\modules\site\controllers\VilleController.php(118): Zend_Db_Select->query() #5 C:\wamp\www\MTK_test2\library\Zend\Controller\Action.php(516): VilleController->rechercheAction() #6 C:\wamp\www\MTK_test2\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('rechercheAction') #7 C:\wamp\www\MTK_test2\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #8 C:\wamp\www\MTK_test2\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() #9 C:\wamp\www\MTK_test2\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #10 C:\wamp\www\MTK_test2\public\index.php(66): Zend_Application->run() #11 {main} Request Parameters: array ( 'controller' => 'ville', 'action' => 'recherche', 'ville' => 'Agadir', 'page' => '1', 'module' => 'site', )
S'il vous palit pouvez vous m'aider?
Merci bien.
Dernière modification par aziza_1989 (09-08-2012 17:12:10)
Hors ligne
Bonjour,
1 - 'chainer' 2 methodes where, c'est pas une erreur ? (c'est juste une question)
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
$select = $db->fetchAll($db->select()
->from(array('e' => 'etablissement'))
->where('e.ville_id = ?', $villeR_id)
->where('e.categorie_id = ?', $categ_id));
2 - Lors de ta requete y'a l'un des array en gras qui est vide.
#0 C:\wamp\www\MTK_test2\library\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\wamp\www\MTK_test2\library\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 C:\wamp\www\MTK_test2\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Select),Array)
Dernière modification par us2rn4m2 (07-08-2012 16:09:52)
Hors ligne
Bonjour,
Tout d'abord merci pour votre interet.
Concernant votre question 1: ce n'est pas une erreur ,les deux where c'est équivalent à "and " veuillez regarder la documanetation:http://framework.zend.com/manual/fr/zend.db.select.html c'est bien expliqué.
Hors ligne