title: How to add a link category_id added to the admin (JToolBarHelper::addNew)? - Joomla 2.5
body: <p>How to add a link <strong>category_id</strong> added to the admin? (Joomla 2.5)</p>
  
  <p>You could write in the function <code>JToolBarHelper::addNew('select.add');</code> or other functions...
  For example, </p>
  
  <blockquote>
    <p>index.php?option=com_pictures&amp;view=select&amp;layout=edit&amp;<strong>category_id</strong>=14</p>
  </blockquote>
  
  <p>Help, please. Thanks in advance</p>
  
  <p><em><strong>Reply David F:</em></strong></p>
  
  <p>Hi, David F. I almost got it.<br/>
  After clicking "Add" appears <code>category_id=14</code>, and the rest did not work after clicking "Edit", "Save", "Save Close" ... - <code>category_id=0</code><br/>
  I've been programming. Here's an example:</p>
  
  <pre><code>...
  protected $catid;
  
  public function __construct($config = array()) {
      parent::__construct($config);
  
      if (empty($this-&gt;catid)) {
          $this-&gt;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-&gt;authorise('core.create', $this-&gt;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-&gt;getModel()-&gt;getItem($recordId)-&gt;catid;
      }
  
      if ($categoryId) {
          return JFactory::getUser()-&gt;authorise('core.edit', $this-&gt;option . '.category.' . $categoryId);
      } else {
          return parent::allowEdit($data, $key);
      }
  }
  
  protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') {
      $append = parent::getRedirectToItemAppend($recordId);
      $append .= '&amp;category_id=' . $this-&gt;category_id;
  
      return $append;
  }
  
  protected function getRedirectToListAppend() {
      $append = parent::getRedirectToListAppend();
      $append .= '&amp;category_id=' . $this-&gt;category_id;
  
      return $append;
  }
  </code></pre>