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?

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.

Comments

  • wzttest1wzttest1 New
    edited April 2013

    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!

  • x00x00 MVP
    edited April 2013

    First consider doing it differently.

    $Sender->AddDefinition('GdnTitle',C('Garden.Title'));
    

    use makejs.js not makejs.php

    and reference it like so

    var gdnTitle = gdn.definition('GdnTitle');
    

    This cuts out of the unnecessary running of code outside of the framework and prevents caching issues.

    grep is your friend.

  • @x00 said:
    First consider doing it differently.

    $Sender->AddDefinition('GdnTitle',C('Garden.Title'));
    

    use makejs.js not makejs.php

    and reference it like so

    var gdnTitle = gdn.definition('GdnTitle');
    

    This cuts out of the unnecessary running of code outside of the framework and prevents caching issues.

    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 so jQuery.parseJSON(gdn.definition('MyDefs'));

    grep is your friend.

  • wzttest1wzttest1 New
    edited April 2013

    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.

  • x00x00 MVP
    edited April 2013

    if you are loading the framework it should be there.

    make sure to reference it within

    jQuery(document).ready(function($){
    
    });
    

    grep is your friend.

  • wzttest1wzttest1 New
    edited April 2013

    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?

  • x00x00 MVP
    edited April 2013

    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.

  • wzttest1wzttest1 New
    edited April 2013

    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.

Sign In or Register to comment.