Add functions for global use by template. - Joomla! Forum - community, help and support


hi, add functions class , use them within template. i'm not sure if on right track, here have far.

i have added php file to: libraries/test/test.php

code: select all

<?php
class test {
   public static function getstring() {
      return 'hello world';
   }
}

i have added new plugin to: plugins/system/test

(plugins/system/test/test.xml contents)

code: select all

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.0" type="plugin" group="system" method="upgrade">
    <name>system - test</name>
    <author>test</author>
    <creationdate>march 2014</creationdate>
    <copyright>copyright (c) 2014 test. rights reserved.</copyright>
    <license>gnu general public license version 2 or later.</license>
    <authoremail>none@none.com</authoremail>
    <authorurl>www.test.com</authorurl>
    <version>1.0.0</version>
    <description>extended class library.</description>
 
    <files>
        <filename plugin="test">test.php</filename>
        <filename>index.html</filename>
    </files>
</extension>

(plugins/system/test/test.php contents)

code: select all

<?php
/**
 * @copyright   copyright (c) 2014 test. rights reserved.
 * @license     gnu general public license version 2 or later.
 */
 
defined('_jexec') or die;
 
/**
 * test plugin class.
 *
 * @package     joomla.plugin
 * @subpackage  system.test
 */
class plgsystemtest extends jplugin
{
    /**
     * method register custom library.
     *
     * return  void
     */
    public function onafterinitialise()
    {
        require_once(jpath_libraries . '/test/test.php');
    }
}

i discovered , installed plugin in extension manager , enabled it.

now display words 'hello world' getstring() function of test class in template.

i tried using:

code: select all

<?php echo getstring(); ?>

code: select all

<?php echo $this->getstring(); ?>

i 'undefined method' error.

what have missed, or doing wrong?

thanks
jay

ah ok, worked out...

i needed create instance of class , use access it's functions:

code: select all

$test = new test();
$hello = $test->getstring();

echo $hello;


hope helps else!





Comments

Popular posts from this blog

Joomla 3.3 Installation Error message - Joomla! Forum - community, help and support

Multilanguage infinite redirect loop error. - Joomla! Forum - community, help and support

trim media limit reached