I tried with second parameter and still nothing.Any route parameters should be passed in the second argument.
category_id
param like this:$this->redirect($this->buildLink('addonid/upload', ['category_id' => 1]));
$params->category_id
/addonid/1/upload
) and that it is routing to the expected action (presumably something like \Your\AddOn\Pub\Controller\AddOnId::actionUpload
).It seems that the code ofAdd a trailing slash to the route format. You should then be able to achieve a redirect to that route with acategory_id
param like this:
PHP:$this->redirect($this->buildLink('addonid/upload', ['category_id' => 1]));
And you should be able to access it in the corresponding controller action via:
PHP:$params->category_id
If that doesn't work, ensure the redirect URL contains the category ID (/addonid/1/upload
) and that it is routing to the expected action (presumably something like\Your\AddOn\Pub\Controller\AddOnId::actionUpload
).
$this->isPost(){ /* Not executing */}
ajax template
, i'm not sure if this is a bug or i'm doing something unexpected.$this->request->isPost(); // still false;
The template where i'm calling is via ajax request, hovever the form submission is via POST.I'm not clear exactly how the action is being called (or the relevance to redirects), but you can use the network inspector of your browser to see how the request is made. It's worth noting that redirects will be GET requests.
// reroutes to actionUploadDifferent on the same controller, adjust as necessary
return $this->rerouteController(__CLASS__, 'uploadDifferent', $params);
This is a little surprising. My understanding was that the second argument should be the entity. Because I seem to have gotten both versions to work:Any route parameters should be passed in the second argument.
$this->buildLink('foo/bar', $user, ['is_changed' => true]);
// this would generate something like foo/bar/some_title.235?is_changed=true
$this->buildLink('foo/bar2', null, ['is_changed' => true]);
// this would generate something like foo/bar2?is_changed=true
\ArrayAccess
, so they behave as an array for route building purposes)._p
will pull them from the third argument instead, for example). public function actionUpload(ParameterBag $params)
{
if(!$params->category_id)
{
return $this->renderCategories();
}
if($this->isPost()) // dump($this->isPost()); return nothing when i submit the form.
{
$categoryId = $this->filter('category_id','int');
if(empty($categoryId))
{
return $this->message(\XF::phrase('no_category_selected'));
}
$category = $this->em()->find('addonid\XF:Category',$categoryId);
if(!$category || !$category->hasPermission('upload'))
{
return $this->message(\XF::phrase('no_permission_to_upload'));
}else{
return $this->rerouteController(__CLASS__,'Upload',['category_id' => (int) $categoryId);
}
}
$categoryId = $this->filter('category_id','int');
$category = $this->em()->find('addonid\XF:Category',$categoryId);
if(!$category)
{
return $this->error(\XF::phrase('category_not_found'));
}
if(!$category || !$category->hasPermission('upload'))
{
return $this->error(\XF::phrase('you_do_not_have_permission_to_upload'));
}
$viewParams = [
'category' => $category
];
return $this->view('','xf_rd_addonid_upload',$viewParams);
}
rerouteController
method doesn't do anything since $this->isPost()
method return nothing. Tried to dump($this->isPost())
and somehow doesn't do anything.$this->isPost()
method. We use essential cookies to make this site work, and optional cookies to enhance your experience.