2012-07-17 95 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();