2013-02-08 68 views
0

我有在的Joomla组件我想调用其他功能相关的问题时,该组件启动组件的Joomla

$controller = JController::getInstance('Productos'); 
$controller->execute(JFactory::getApplication()->input->get('task')); 
$controller->redirect(); 

这里我要调用一个函数在数据库中只选择一个项目不是所有

Ÿ试试这个

$controller->execute(JFactory::getApplication()->input->get('other')); 

,并在我的

class ProductosController extends JController 
{ 

function Other(){ 
... 
} 

} 

但我的代码从来没有通过其他功能。

出了什么问题?

回答

1

JFactory::getApplication()->input->get('task')将返回一个控制器/函数对或只是一个函数名。如果它是一个控制器/函数对,它将以这种格式返回一个字符串:'controller.function'。注意一段时间的分离。如果返回一个函数,它将只是函数名称。

您对脚本所做的修改导致它寻找名称为“other”而不是名称“task”的请求变量(即post或者get variable)。 (任务是标准的Joomla变量传递的任务。)

如果你真的想总应该调用特定的功能,你会改变行这样的:

$controller->execute('Productos.other'); 

同样,你也可以只适应页面正在调用这一点,所以该URL或者包含task=productos.other或有一个隐藏的输入表单字段像这样:

<input type="hidden" name="task" value="productos.other" /> 
0

调用的更好的方式控制方法是:

$controller = JControllerLegacy::getInstance('Other'); 
$controller->execute(JFactory::getApplication()->input->getCmd('task')); 

使用getCmd()调用控制器任务,并且任务不在URL中传递,因此您无法使用get()方法获取任务。

试试这个代码,并得到你的问题的解决方案。