We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Basic variable help for plugin

Development and Programming

Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

I’m trying to make a plugin this morning and I have two questions.

1) How can I reference $_SERVER[‘DOCUMENT_ROOT’]? If so, is there an ‘approved’ way to do this, through some class (Input?)? I can’t seem to find what I’m looking for and for some reason can’t find another plugin/extension in my collection that has an example I can reference. I just want to set a variable equal to the document root, if possible.

2) I apparently can’t link together variables inside my class?

I have something similar to this inside my class definition:

var $var1 = 'something ';
var $var2 = $var1.'in the way';

I would expect that if I then used $var2, it would be equal to “something in the way”. Instead, my template is throwing this error:

Parse error: syntax error, unexpected T_VARIABLE in 
/home/.../.../system/plugins/pi.myplugin.php on line 35

where line 35 is the ‘var $var2’ line. Doesn’t seem to like that! Thanks for help with this.

       
silenz's avatar
silenz
1,648 posts
17 years ago
silenz's avatar silenz

Quote from the PHP manual:

In PHP 4, only constant initializers for var variables are allowed. To initialize variables with non-constant values, you need an initialization function which is called automatically when an object is being constructed from the class. Such a function is called a constructor (see below).
class mdesign
  {
      var $var1;
      var $var2;
     
      function mdesign()
      {

        $this->var1 = 'something ';
        $this->var2 = $this->var1.'in the way';  
          
         echo $this->var2 . '<hr >';
          
         var_dump($_SERVER['DOCUMENT_ROOT']);
      }
  }
       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

You might want to check the $PREFS global for the document root.

[/code] <?php global $PREFS; print_r($PREFS); exit; ?>[/code]

You will need to place that in an extension / plugin to see the output.

Cheers Leevi

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

Thanks for the help, guys. That stuff s what I needed.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.