Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How to call Gdn::Config('Garden.Title') in my plugin?
wzttest1
New
Hi:
I want to call Gdn::Config('Garden.Title') for getting the forum title for my plugin,but I got the PHP Fatal error: Class 'Gdn' not found in ... error info.
What should I do?
Any help would be appreciative.
0
Comments
Sorry for the unclearly topic.
My exact issue is:
I need call Gdn::Config('Garden.Title') in a separate php program,this php program need get the Gdn::Config('Garden.Title') returned value and output js code,and my plugin code will add this js file(maked by the php code),looks like this:
$Sender->AddJsFile('/pathinfo/makejs.php');
How to make Gdn::Config('Garden.Title') run in the makejs.php?
Thanks!
First consider doing it differently.
use
makejs.js
notmakejs.php
and reference it like so
This cuts out of the unnecessary running of code outside of the framework and prevents caching issues.
grep is your friend.
Hi:
Thank you for your help.
You mean the following code should be in my plugin php file to define a constant for js?
$Sender->AddDefinition('GdnTitle',C('Garden.Title'));
And the following code should be in my js file to get the constant?
var gdnTitle = gdn.definition('GdnTitle');
sure thing. If you hav a lot of variable instead of cluttering up the definition,
json_encode
and array of values, and retrieve them like sojQuery.parseJSON(gdn.definition('MyDefs'));
grep is your friend.
I wrote these two line codes in my the makejs.js file:
var test = gdn.definition('GdnTitle'); alert(test);
But I got the js error info:
gdn is not defined.
if you are loading the framework it should be there.
make sure to reference it within
grep is your friend.
Sorry for my unclearly description.
I include the js code like this in my plugin affected pages:
<script src="/vanilla_2-0-18-4/dirname/makejs.js?v=2.0.18.4" type="text/javascript"></script>
And the code in the makejs.js is:
var test = gdn.definition('GdnTitle'); alert(test);
And I got the js error info:
gdn is not defined.
You mean I should write js code in makejs.js like this?
jQuery(document).ready(function($){ var test = gdn.definition('GdnTitle'); alert(test); }
Please work through and try, I offer guidance only
grep is your friend.
Hi:
It's working well.
Thank you very much.
But I need the js run before page dom loaded,I mean is there any other way to make the js running before the page dom loaded?
the definition is in the dom, you could pass the variable through inline script. use
$Sender->Head->AddString('...')
I would define the variable, and call a function within this.Figure out the rest.
grep is your friend.
Hi,
The jQuery(document).ready() method will wait the dom loaded,so the $Sender->Head->AddString('...') would works as same as in makejs.js.
Thanks.
Hi:
I think I have found the right way for my requirement.
I should directly write js code with the $Sender->Head->AddString('...') method instead of the $Sender->AddDefinition('GdnTitle',C('Garden.Title')); and the var test = gdn.definition('GdnTitle');
Thank you for your help!
But the added string maked by the $Sender->Head->AddString('...') method is always behind the js file maked by the $Sender->AddJsFile() method,and my requirement need the added string running before the added js file,so it is the only issue now.
please reread my answer, the solution is there.
Revise your coding style.
grep is your friend.