Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Url Handlers exclude SearchForm


Go to End


917 Views

Avatar
Praveen

Community Member, 49 Posts

11 November 2014 at 5:23pm

Edited: 12/11/2014 1:50am

I have a PageTag which shows all the Pages matching a Tag Name passed in the url.

where tags is the pagename
http:://<website>/tags/<slug> it shows the Pages related to the tag
http:://<website>/tags/SearchForm it should redirect to the searchform page

I want to exclude the SearchForm from the slug. Because there is already a action with that name.

class PageTag_Controller extends Page_Controller
{
	static $allowed_actions = array(
		'index',
		'specificTags',
	);
	public static $url_handlers = array(
		'$Slug!' => 'specificTags',
		'' => 'index'
	);
        function index() {	

		$data = array(
			'Results' => array()
		);			
		return $this->->renderWith('PageTag');
        }
	//UrlHandelres not redirecting Hence using common methods to all
	//Controller

	function specificTags() {
                $Slug = $this->request->param('Slug');
		$Tag = Tag::get()->filter('slug',$Slug)->first(); 

		if($Tag) {
			if($Slug == 'SearchForm'){
                             $this->owner->redirect('SearchForm')
                        }

                      return $this->renderWith('PageTag');
       }
}

How do I exclude the SearchFrom from the Url handlers directing to the function specificTags?

Above code still works but I need to include condition in the specificTags function to check whether slug is SearchFrom otherwise it will not work.

Page_Controller::add_extension('ExtensibleSearchExtension');
class ExtensibleSearchExtension extends Extension {

	function SearchForm() {
        }

 	public function results() {
        }
}