2012-07-17 91 views
2
大家

您好我沒在的Joomla 2.5後端組件,但我有問題執行SQL查詢,我的變量是空的,所以它鴕鳥政策告訴我什麼。中的Joomla執行sql查詢

我有其他文件和文件,但這裏對我的問題很重要。

先在我Controller.php這樣我有這個內部管理文件

class BusquedaController extends JController 
{ 
    protected $default_view= 'restaurantes'; 
    public function display(){ 
    parent::display(); 
    } 
} 

在我的模型文件我有restaurante.php

class BusquedaModelRestaurante extends JModelList{ 
    function getListaRestaurantes(){ 
     $db= JFactory::getDBO(); 
     $sql= "SELECT * FROM #__restaurantes"; 
     $db->setQuery($sql); 
     return $db->loadObjectList(); 
    } 
} 

在我的控制器文件我有這個

class BusquedaControllerRestaurantes extends JControllerAdmin 
{ 

    public function getModel($name = 'Restaurante', $prefix = 'BusquedaModel', $config = array('ignore_request' => true)) 
    { 
     $model = parent::getModel($name, $prefix, $config); 
     return $model; 
    } 

    function listado(){ 
     $firephp->log('hola'); 
     $view=& $this->getView('restaurantes', 'html'); 
     $model= $this->getModel("restaurante"); 
     $listaMensajes= $model->getListaRestaurantes(); 
     $view->assignRef('resList', $listaMensajes); 
     $view->display(); 
     } 
} 

終於在我查看文件我有我如default.php,顯示錶中的TMPL文件

foreach ($this->resList as $item): 
     $checked=JHTML::_('grid.id', $n, $item->id); ?> 
      <tr> 
       <td><?php echo $checked; ?></td> 
       <td><?php echo $item->id; ?></td> 
       <td><?php echo $item->nombre; ?></td> 
       <td><?php echo $item->direccion; ?></td> 
       <td><?php echo $item->telefono; ?></td> 
       <td><?php echo $item->web; ?></td> 
       <td><?php echo $item->tipo; ?></td> 
       <td><?php echo $item->zona; ?></td> 
       <td><?php echo $item->metro; ?></td> 
      </tr> 
      <?php 

,但該元素reslist是空的,我不知道如果我做我的組件嘛!!有人知道一個教程或東西的Joomla 2.5

感謝做一個組成部分!

回答

-2

看看我們Joomla Component Creator。我想你會發現它很有用。

我會建議堅持MVC框架儘可能和使用getItems()等只需複製什麼com_weblinks在做什麼。或者更好 - 讓組件創建者爲你做這一切。

0

嘗試增加你的分量開始的error_reporting(E_ALL),它有望告訴你幹嘛呢錯了。

如果不幫忙看看該查詢getListaRestaurantes()方法,通過simplle print_r($db->loadObjectList()); jexit();

附:返回在JModels可以使用$此 - > _ DB獲得參考JDatabase對象(而不是JFactory :: getDBO())

0

試試這個,改變$ listaMensajes被$ this-> resList在控制器

$ this-> resList = $ model-> getListaRestaurantes();

0

拋出運行時間異常

try 
{ 
    $db->setQuery($query); 
    $result = $db->loadResult(); // If it fails, it will throw a RuntimeException 
} 
catch (RuntimeException $e) 
{ 
    throw new Exception($e->getMessage()); 
} 

也在控制器聲明爲保護的

protected $resList; 

分配值給變量像變量

$this->resList = $model->getListaRestaurantes();