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.

General Questions

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

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

pass variable to other controller


6 Posts   656 Views


9 May 2012 at 3:21am Community Member, 4 Posts

Is it possible to call a function which is in the page_controller, from the member controller?

I tried differrent things like:


But I haven't found a nice solution yet.
Is there one?


9 May 2012 at 5:53am (Last edited: 9 May 2012 5:54am), Forum Moderator, 1091 Posts


you can instantiate any class, so you could probably do something like:

$myController = new Page_Controller();

In that case there is no referrence to a specific page though, your're just using the Page_Controller class to execute a Page_Controller function. I can't really think of situation where you would need to do that? And you wouldn't want to change core functionality in the member class I would think... So maybe I'm not understanding this correctly?


9 May 2012 at 7:49pm Community Member, 4 Posts

I tried that, but it doesn't seems to work. Maybe I'm doing something else wrong.
Here is a snippet of my code:

class SocketServer extends Page_Controller{
static $allowed_actions = array(
'delete', 'Delete_tig',

public function Delete_user(){
if(this->ID==3) {
return true;
return false;


class Employee extends Member {
public function onBeforeDelete(){

So I'm trying to call the Delete_user() function from my extended Employee class


10 May 2012 at 10:33pm Forum Moderator, 1091 Posts

I'm sorry, I couldn't get back to you sooner, as my forum login for some reason stopped working. It seems to be OK now, so...

I don't think the Member object has access to a $ParentController property, so unless you defined it somewhere in your Employee class, it probably is never going to pass that filter.

Maybe you could tell me more about what it is you actually want to achieve - there might be an easier way?


10 May 2012 at 11:58pm Community Member, 4 Posts

No problem :) I had the same problem, thnx for getting back!

I'm pretty new to silverstripe and I think I'm not understanding te sturcture good enough yet.
What I would like to achieve is this:

If a user is deleted, the onBeforeDelete() is called. With function I would like to call the Delete_user() function which then creates a TCP connection to another device in which the user also has to be deleted.

Currently I have written the Delete_user() function in the SocketServer class which extends the Page_controller. Is that the right way to do it?
Or should I make SocketServer an extension which can be called from my Employee class? If so how am I able to call the function in the extension from my employee class?


11 May 2012 at 12:50am (Last edited: 11 May 2012 12:52am), Forum Moderator, 1091 Posts

As for the SocketServer extending Page_Controller - I probably wouldn't do that. A Page_Controllers main task, I guess, is to control how a page behaves. Being a SocketServer wouldn't really be part of that. Speaking for my self here, of course :-)

I don't know if you're using specific SilverStripe functionality to build your socketserver connection functionality. If so, then you should make sure your SocketServer class extends whatever class is needed to support that functionality. Otherwise Object [EDIT] or none?[/EDIT] would even be enough...

The following should work:

$socketServerObj = new SocketServer();
$result = $socketServerObj->DeleteUser($SomeIdentification);