HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How can I access DiscussionModel data in DiscussionController Object?

I have following "problem": I want to access the info from table Media that are connected to a special discussion.

At first I thought I have to query the Media table, but I found out that all the relevant informations are already in the DiscussionController. Look at what I get when I do a decho($sender) from any DiscussionController event:


As you can see $sender->DiscussionModel->DataBase->_CurrentResultSet->_Result shows information about the connected Medias (in fact all relevant informations are already there!). But since they are protected, I do not have access to them :(

I do not want to query the db for information of the Media if it is already availabe in the DiscussionController, but I cannot find a way to use this information. Does anybody has a hint for me?

Best Answers

Answers

  • decho($sender)

    Aside your question which I cannot contribute to, just wanted to thank you for posting this helpful code snippet to inspect $Sender objects :+1:

  • Thanks @peregrine, I'll try to understand that.
    @x00: do you mean that if I find a DiscussionModel as a part of the DiscussionController, I could access that DiscussionModel also on another way? Is there a way to examine "the whole scope" - do you have a hint for a starting point?

    In the meantime I do not need that anymore, but I'm still curious.

  • @oliverraduner said:
    Aside your question which I cannot contribute to, just wanted to thank you for posting this helpful code snippet to inspect $Sender objects :+1:

    Sometimes you will not be able to see the output unless you stop the process: decho($sender); die; But for sure you cannot do this in your live system.

    You can also write to your file system file_put_contents('/var/log/nginx/vanilla.log', print_r($sender, true));. Certainly you need to change the file path according to your needs.

    And while writing this down, I thought of creating a helper function for myself! I've added this function to my /conf/bootstrap.before.php file:

    function d($output = '', $destination = '/var/log/nginx/vanilla.log') {
        if ($output === '') {
            $output = debug_backtrace();
        } elseif (!is_string($output)) {
            $output = print_r($output, true);
        }
        file_put_contents($destination, $output);
    }
    

    Not yet tested it and I'm not sure if using d() without parameters will give useful information, but you can use d($sender) to dump the contents of the variable to a file if decho() is not usable.

Sign In or Register to comment.