2013-02-08 43 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()方法獲取任務。

試試這個代碼,並得到你的問題的解決方案。