繁体   English   中英

如何添加添加到管理员(JToolBarHelper :: addNew)的链接category_id? -Joomla 2.5

[英]How to add a link category_id added to the admin (JToolBarHelper::addNew)? - Joomla 2.5

如何添加添加到管理员的链接category_id (Joomla 2.5)

您可以在函数JToolBarHelper::addNew('select.add'); 或其他功能...例如,

index.php?option = com_pictures&view = select&layout = edit& category_id = 14

请帮忙。 提前致谢

回复David F:

嗨,DavidF。我几乎明白了。
单击“添加”后,将显示category_id=14 ,其余部分在单击“编辑”,“保存”,“保存关闭”后将无法使用...- category_id=0
我一直在编程。 这是一个例子:

...
protected $catid;

public function __construct($config = array()) {
    parent::__construct($config);

    if (empty($this->catid)) {
        $this->catid = JRequest::getInt('category_id', 0);
    }
}

protected function allowAdd($data = array()) {
    $user = JFactory::getUser();
    $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int');
    $allow = null;

    if ($categoryId) {
        $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId);
    }

    if ($allow === null) {
        return parent::allowAdd($data);
    } else {
        return $allow;
    }
}

protected function allowEdit($data = array(), $key = 'id') {
    $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
    $categoryId = 0;

    if ($recordId) {
        $categoryId = (int) $this->getModel()->getItem($recordId)->catid;
    }

    if ($categoryId) {
        return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId);
    } else {
        return parent::allowEdit($data, $key);
    }
}

protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') {
    $append = parent::getRedirectToItemAppend($recordId);
    $append .= '&category_id=' . $this->category_id;

    return $append;
}

protected function getRedirectToListAppend() {
    $append = parent::getRedirectToListAppend();
    $append .= '&category_id=' . $this->category_id;

    return $append;
}

我相信您正在寻找的功能是JController的一部分,应该添加到您的控制器中。 在您的情况下,这可能是基于URL中视图名称的select.php控制器。

您可以在类别组件中看到一个很好的示例,特别是在administrator / components / com_categories / controllers / category.php中。

以下是com_categories中的代码。 您可能希望将扩展名重命名为“ category_id”,并且可能想要从JInput而不是当前类中获取值:

/**
 * Gets the URL arguments to append to an item redirect.
 *
 * @param   integer  $recordId  The primary key id for the item.
 * @param   string   $urlVar    The name of the URL variable for the id.
 *
 * @return  string  The arguments to append to the redirect URL.
 *
 * @since   1.6
 */
protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
{
    $append = parent::getRedirectToItemAppend($recordId);
    $append .= '&extension=' . $this->extension;

    return $append;
}

/**
 * Gets the URL arguments to append to a list redirect.
 *
 * @return  string  The arguments to append to the redirect URL.
 *
 * @since   1.6
 */
protected function getRedirectToListAppend()
{
    $append = parent::getRedirectToListAppend();
    $append .= '&extension=' . $this->extension;

    return $append;
}

*编辑:

您还必须将其添加为表单的一部分。 这是简单但重要的部分。 只要确保表单具有带有值的隐藏输入,或将其添加到表单的操作部分中的url中即可:

<form action="<?php echo JRoute::_('index.php?option=com_component&layout=edit&id='.(int) $this->item->id . '&category_id='.$this->category_id); ?>" method="post" name="adminForm">

或使用此:

<input type="hidden" name="category_id" value="<?php echo $this->category_id; ?>" />

为了进一步说明会发生什么,当您单击某项以转到表单时,您可能会添加所需的变量。 然后将其添加到表单,以便单击其中一项时,它将随表单一起提交。 Joomla会处理此表单,并根据单击的工具栏按钮保存或不保存。 然后,Joomla重定向回到表单或列表视图。 没有控制器中的功能,变量将丢失。

暂无
暂无

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

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