Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-02-10 04:19:16

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Classes in plugins

edit: Solved – thanks Manfre!

function jmd_example($atts)
{
	global $jmd_example_instance, $thisarticle;
	/*
		$jmd_example_instance is a public-side global variable.
		you could also call it $jmd_example - we've already got 
		jmd_example() and JMD_Example, so why not?
	*/
	$jmd_example_instance = new JMD_Example($thisarticle['title']);

	return $jmd_example_instance->doStuff();
}

function jmd_example_baz($atts)
{
	return $GLOBALS['jmd_example_instance']->doOtherStuff();
}


class JMD_Example
{
	public $name;

	public function __construct($title)
	{
		$this->name = $title;
	}

	public function doStuff()
	{
		return $this->name;
	}

	public function doOtherStuff()
	{
		return strtoupper($this->name);
	}
}

edit: prefixed the class and instance

Last edited by jm (2008-03-29 06:21:06)

Offline

Board footer

Powered by FluxBB