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.
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']);
}
}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.