PHP Question
I was thinking about creating a little plugin that makes navigating through the long list of plugins easier by providing an alphabetical shortcut list. This is what I started with:
class PluginNavigatorPlugin extends Gdn_Plugin { public function SettingsController_BeforeRenderAsset_Handler($Sender) { // stop if not Content of Plugins section if (($Sender->EventArguments['AssetName'] != 'Content') || (substr($Sender->SelfUrl,0, 16) != 'settings/plugins')) { return; } $Content = $Sender->Assets['Content']; // some regex magic here $ContentNew = preg_replace('/(< div class="Info">)/', '$1Index: A B C D E F...< /div>$1', $Content); $Sender->Assets['Content'] = $ContentNew; } }
Looks clean and easy but does not do anything
If I look at where the event is fired, I see this (class.controller.php):
public function RenderAsset($AssetName) { $Asset = $this->GetAsset($AssetName); $this->EventArguments['AssetName'] = $AssetName; $this->FireEvent('BeforeRenderAsset'); //$LengthBefore = ob_get_length(); if(is_string($Asset)) { echo $Asset; ...
So I would have to change the var $Asset in the scope of the function RenderAsset. Is this possible?
Best Answers
-
hgtonight MVP
No.
There are other approaches to do what you want to do, but as far as I know, there is no way to access variables out of scope.
EDIT: Clever regex, btw.
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
5 -
peregrine MVP
edited out.
back in again.
the dreaded reflection methods.
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
No.
There are other approaches to do what you want to do, but as far as I know, there is no way to access variables out of scope.
EDIT: Clever regex, btw.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Yes, I've thought about js and later on I remembered I could simply create a custom view. I think I simply create such a view. Thanks for answering even simple php questions
edited out.
back in again.
the dreaded reflection methods.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
But it was also true
ok edited back in. But perhaps I wish I didn't.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.