Is it possible to call a function which is in the page_controller, from the member controller?
I tried differrent things like:
$this->parentController->hasMethod(Delete_tig)
But I haven't found a nice solution yet.
Is there one?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Is it possible to call a function which is in the page_controller, from the member controller?
I tried differrent things like:
$this->parentController->hasMethod(Delete_tig)
But I haven't found a nice solution yet.
Is there one?
Hi,
you can instantiate any class, so you could probably do something like:
$myController = new Page_Controller();
$myController->doSomething();
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?
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) {
//delete
return true;
}
return false;
}
member:
class Employee extends Member {
public function onBeforeDelete(){
if($this->parentController->Delete_user()){
parent::onBeforeDelete();
exit;
}else{
exit;
}
}
}
So I'm trying to call the Delete_user() function from my extended Employee class
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?
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?
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);