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
-
peregrine MVP
there are some discussions on forum relating to reflection
http://php.net/manual/en/book.reflection.php
that discuss something similar iirc.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
5
Answers
there are some discussions on forum relating to reflection
http://php.net/manual/en/book.reflection.php
that discuss something similar iirc.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
You shouldn't need reinfection, you need to find the actual object, if it is being use it will be loaded at some point.
I can tell you how to get the result set, but you are assuming it is always goign to be there. This is something transient.
grep is your friend.
Aside your question which I cannot contribute to, just wanted to thank you for posting this helpful code snippet to inspect $Sender objects
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.
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: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 ifdecho()
is not usable.