简体   繁体   English

Joomla:在自定义视图中保存表单时出错

[英]Joomla: error while saving form in custom view

I have created a custom component with form to update prices of four product to be displayed on frontend. 我创建了一个带有表单的自定义组件来更新要在前端显示的四个产品的价格。

My main controller code is here: 我的主控制器代码在这里:

public function display($cachable = false, $urlparams = false) {

    require_once JPATH_COMPONENT.'/helpers/calculator.php';

    $view       = JFactory::getApplication()->input->getCmd('view', 'pricetable');
    $layout     = JFactory::getApplication()->input->getCmd('layout', 'edit');

    JFactory::getApplication()->input->set( 'layout', $layout );
    JFactory::getApplication()->input->set('view', $view);
    JFactory::getApplication()->input->set('id', 1);

    parent::display($cachable, $urlparams);
    return $this;
}

id is set to 1 so it loads only first row from database. id设置为1,因此它只加载数据库的第一行。

code for pricetable container is: pricetable容器的代码是:

function __construct() {
    $this->view_list = 'pricetable';
    parent::__construct();
}

Now in admin backend the form is loaded as desired with the first row of data. 现在在admin后端,表单根据需要加载第一行数据。 When I try to save the form it is redirected to administrator/index.php?option=com_calculator&view=pricetable and error is: 当我尝试保存表单时,它会被重定向到administrator/index.php?option=com_calculator&view=pricetable ,错误是:

Error: You are not permitted to use that link to directly access that page (#1). 错误:您不允许使用该链接直接访问该页面(#1)。

my form action is: 我的表格动作是:

<?php echo JRoute::_('index.php?option=com_calculator&task=pricetable.edit&id='.(int) $this->item->id); ?>

Please suggest where I am doing wrong. 请告诉我哪里做错了。 It is third day I'm scratching my head. 这是第三天我在挠头。 :( :(

You can do updating actions (or calling them) inside your code whenever it is. 您可以在代码中更新操作(或调用它们)。 New instance or update new - just add one more if in code and hidden input on form. 新实例或更新新的-只是多加一个if在代码和hidden输入上的形式。 For example: 例如:

<input type="hidden" name="task" value="update" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM