0

I don't understand how to retrieve some post data into specific method in controller. After submiting the form, the script goes into batch_categories() method into the controller in this method i define some specifics post variable to try retrieve them into _save() :

public function batch_categories()
{
  $cid = $this->app->input->get('cid', '', 'array'); 
  if ( $task == 'copy' )
    {
        $categories = $this->getCategories($cid);

        foreach ($categories as $cat)
        {
            list($title, $alias) = $this->_generateNewTitle($cat->id, $cat->alias, $cat->name);

            $_POST['name']  = $title;
            $_POST['alias']  = $alias;
            $_POST['parent_id'] = intval($cat_parent);
            $_POST['catid'] = 0;      
            $this->_save();
        }

        $this->app->enqueueMessage(JText::_('BATCH_COPY_SUCCESS'));
    }
}

In the save _save below, in the post data there ins't name, alias, parent_id, catid. Before with JRequest it worked well, now with JInput it doesn't work :

protected function _save()
{
 $post       = $this->app->input->getArray();
}

I need to know how to retrieve in _save() method, the differents posts variables (name, alias, parent_id, catid) defined in the batch_categories() method.

Thanks by advance

1

Set the values directly on the jinput instead of setting them on PHP globals.

$app->input->set('title', $title);

Why don't you pass the values directly to the _save() method instead of setting them in PHP globals (it is not recommended to access PHP globals directly)?

$args = new stdClass();
$args->title = $title;
$args->alias = $alias;
$args->parent = intval($cat_parent);
$args->catid = 0;
$this->_save($args);

Change signature of _save method to accept an argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.