Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » pass variable to other controller

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

Page: 1
Go to End
Author Topic: 548 Views
  • Lens-Art
    Avatar
    Community Member
    4 Posts

    pass variable to other controller Link to this post

    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?

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: pass variable to other controller Link to this post

    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?

  • Lens-Art
    Avatar
    Community Member
    4 Posts

    Re: pass variable to other controller Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: pass variable to other controller Link to this post

    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?

  • Lens-Art
    Avatar
    Community Member
    4 Posts

    Re: pass variable to other controller Link to this post

    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?

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: pass variable to other controller Link to this post

    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);

    548 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.