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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Attaching and Action to a Link [SOLVED}


Go to End


3 Posts   1277 Views

Avatar
zenmonkey

Community Member, 545 Posts

28 September 2009 at 5:07am

Edited: 28/09/2009 11:17am

I'm currently building a function that switches a the site template for Mobile browsers. I'm trying to include an override for browser's such as Safari iPhone that can go to the default site. My Solution so far is to render a form with only an action that will override the mobile phone detection. Is there anyway to tie this function to a standard link anchor instead of a form button? Once again probably something simple I'm just having trouble forming the right search query for. Below is my current code:

//Overide Mobile Theme
	function MobileOveride(){
		if($_SESSION['mobilePhone'] != "None"){
			$fields = new FieldSet();
			$actions = new FormAction('overideMobile','View Standard Site');
			
			return new Form($this, "MobileOveride", $fields, $actions);	
		}
		else
		{
			return false;
		}
	}
	
	function overideMobile() {
		$_SESSION['mobilePhone']="None";
		Director::redirect(Director::baseURL(). $this->URLSegment);
	}

Avatar
Willr

Forum Moderator, 5523 Posts

28 September 2009 at 9:03am

If you just want to call that function from a link - you can call methods in this format - http://www.yoursite.com/ClassName/MethodName. So if that code is in your Page_Controller class you could write the link as <a href="home/overideMobile">Link</a>

Avatar
zenmonkey

Community Member, 545 Posts

28 September 2009 at 11:16am

Thanks I knew it was something simple that and I just wasn't searching for the right key words

Thanks again Willr