【问题标题】:File Uploader in JoomlaJoomla 中的文件上传器
【发布时间】:2012-12-31 11:32:45
【问题描述】:

我一直在关注文档here 向现有组件添加(改进的)文件上传部分。

上例中的控制器/模型的链接是通过 post 参数形成的,然后处理上传:

    post_params: 
    {
            "option" : "com_mycomponent",
            "controller" : "mycontroller",
            "task" : "mytask",
            "id" : "'.$myItemObject->id.'",
            "'.$session->getName().'" : "'.$session->getId().'",
            "format" : "raw"
    }, 

我的问题是使用 Joomla 2.5 中引入的新控制器方法无法上传:

// Get an instance of the controller prefixed by the component
$controller = JController::getInstance('mycomponent');

// Perform the Request task
$controller->execute(JRequest::getCmd('task'));

// Redirect if set by the controller
$controller->redirect();

这工作(确实在 Joomla 2.5 上)在旧的 1.5 加载控制器方法上工作得非常好:

// Create the controller
$classname  = 'mycomponentController'.$controller;
$controller = new $classname( );

// Perform the Request task
$controller->execute( JRequest::getVar('task'));

// Redirect if set by the controller
$controller->redirect();

虽然后一种方法与 Joomla 2.5 兼容,但不幸的是,我希望与之集成的组件使用了较新的方法,我不想更改它,因此我可以根据需要不断更新组件,而不必每次都更改它。另外,如果我确实更改了它,我猜我可能会失去现有的功能。

基本上我想知道如何设置后参数,以便正确调用新的控制器方法!


编辑

此后我尝试使用以下参数配置:

post_params: 
{
    "option" : "com_mycomponent",
    "task" : "mycontroller.mytask",
    "id" : "'.$myItemObject->id.'",
    "'.$session->getName().'" : "'.$session->getId().'",
    "format" : "raw"
}, 

我试图模仿index.php?option=com_mycomponent&task=mycontroller.mytask 等的链接。但这仍然不起作用

【问题讨论】:

    标签: joomla joomla2.5 swfupload


    【解决方案1】:

    您需要在 index.php 中定义以下变量

    define('_JREQUEST_NO_CLEAN', 1);
    

    我一直在寻找原因,我发现了这个—— http://docs.joomla.org/Framework_Compatibility

    注意-如果这不起作用删除"format" : "raw"

    如果它不起作用,请告诉我。

    【讨论】:

    • 当你在 index.php 中说这是在主(管理员)根 Joomla index.php 文件中吗?
    • @GeorgeWilson:如果您在 admin 中工作,那么它将是前面的管理员。
    • 抱歉这么久才回复这个问题 - 但我仍然遇到同样的 500 错误问题!
    • @GeorgeWilson:你缺少token than.add token也带有参数。
    • 好的,抱歉,我刚刚注意到您关于删除 format:raw 的初步想法 - 试了一下,效果很好。甚至不需要define('_JREQUEST_NO_CLEAN', 1);。不太清楚为什么这与旧版本有如此大的不同——如果你能解释一下,将不胜感激——但非常感谢你解决它!
    猜你喜欢
    • 2011-10-29
    • 2012-06-14
    • 2012-07-30
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多