簡體   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