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

MyPage class and using magic __call()


Go to End


1190 Views

Avatar
SunboX

Community Member, 5 Posts

25 May 2009 at 3:06am

Hi,

i would write something like:

public function __call($action, $args)
{
	switch($action)
	{
		case 'edit':
			if(Permission::check('ADMIN') || (is_numeric($this->urlParams['ID']) && $this->urlParams['ID'] == Member::currentMember()->ID))
			{
				$this->Content = $this->EditProfileForm();
				break;
			}
				
		case 'show':
			$this->Content = 'Und hier kommt die Maus...';
			break;
	}
		
	return $this;
}

But that doesn't work. Instead i have to write:

public function edit() { return $this->doAction('edit'); }
public function show() { return $this->doAction('show'); }

public function doAction($action)
{
	switch($action)
	{
		case 'edit':
			if(Permission::check('ADMIN') || (is_numeric($this->urlParams['ID']) && $this->urlParams['ID'] == Member::currentMember()->ID))
			{
				$this->Content = $this->EditProfileForm();
				break;
			}
			
		case 'show':
			$this->Content = 'Und hier kommt die Maus...';
			break;
	}
	
	return $this;
}

Why can't i use the __call() magic?

thx Sunny

PS:

I know, i can write something like this:

public function edit()
{
	if(Permission::check('ADMIN') || (is_numeric($this->urlParams['ID']) && $this->urlParams['ID'] == Member::currentMember()->ID))
	{
		$this->Content = $this->EditProfileForm();
		return $this;
	}
	return $this->show();
}

public function show()
{
	$this->Content = 'Und hier kommt die Maus...';
	return $this;
}

;o) but the use of __call() would be nice.