用joomla组件刷新页面

问题描述 投票:0回答:1

我的tmpl / default.php中有一个简单的表单:

<form id='AddForm' action="<?php echo JRoute::_('index.php?option=com_mycomponent&task=addcam'); ?>" >
            <p>
            <label for="CamName">Name:
            </label>
            <input type="text" id="CamName" name="cam_name" />
            </p>
            <button type='submit' class='submit_cam' name='addcam' value='Add'>Add</button>
            <button type='reset' class='cancel_changes' name='cancel_changes' value='Cancel'>Cancel</button>
        </form>

在我的controller.php文件中,我试图处理这些值:

function addcam()
{
    $add_name=JRequest::getString('cam_name');
    $model = &$this->getModel();
    $model->AddWebcam($add_name); //send to model to add to DB
}

在我的模型中,我只是返回查询结果。 通过这种实现,我只是被路由到一个空白页面。 我想让它刷新当前页面。 通常,您可以使用action=""执行此action=""但就我而言,我需要它路由到控制器中名为addcam的函数。 还是有更好的方法来做到这一点?

model-view-controller joomla joomla2.5
1个回答
1
投票

在Joomla中,执行任务的一种常见技术是让该函数在最后完全重定向到视图。 这样可以防止页面刷新尝试重新提交数据,并导致客户端的URL更干净。 为此,请尝试以下操作:

function addcam()
{
    $add_name=JRequest::getString('cam_name');
    $model = &$this->getModel();
    $model->AddWebcam($add_name); //send to model to add to DB
    JFactory::getApplication()->redirect(JRoute::_(index.php?option=com_mycomponent&view=whatever));
}

显然,将JRoute位更新为实际需要的URL。 您还可以根据需要添加一条消息(例如“已保存!”): http : //docs.joomla.org/JApplication :: redirect/1.6

© www.soinside.com 2019 - 2024. All rights reserved.