How can i add a method to the RaxanElement

A place to share your Plugins and Extensions

How can i add a method to the RaxanElement

Postby orson4music » Tue Jul 13, 2010 5:51 pm

I know this works:
Code: Select all
RaxanElement::addMethod('cleintMethodName', 'scriptMethodName')


The question is that i want to use the addMethod function of the RaxanElement class from within the page_load of my plugin class. That means, i will be calling an instance method from within my plugin class.

How do i do that please?

Example

Code: Select all
<?php
class Table extends RichPlugin {

    function page_load($e, $page){       
        RaxanElement::addMethod('cleintMethodName', array($this, 'render')); //something like this
    }

    public function render() {

    }
}
?>
orson4music
 
Posts: 20
Joined: Sun Jun 13, 2010 11:40 am

Re: How can i add a method to the RaxanElement

Postby raymond » Tue Jul 13, 2010 7:17 pm

Hi,

Here's an example of how it can be done:

For the plugin you can extend RaxanElement within the page_init or system_init methods.

table.php
Code: Select all
<?php
class Table extends RaxanPlugin {
    public static $name = 'Table Plugin';
    public static $description = "Table description goes here";
    public static $author = "Author's Name";
    protected function methods() { return get_class_methods($this); }
    public static function register() { return self::instance(__CLASS__); }

    protected function page_init($e,$page) {
        RaxanElement::addMethod('clientMethodName', array($this, 'render')); //extend RaxanElement
    }

    public function render($elm) {
        $elm->css('font-weight','bold'); // make font bold
    }
}
Table::register();
?>


And inside the web page you can use it as you normally would

webpage.php
Code: Select all
<?php

require_once 'raxan/pdi/autostart.php';
include_once 'raxan/plugins/table.php';

// web page
class NewPage extends RaxanWebPage {
    protected function _load() {
        $this->myelement->clientMethodName(); // call plugin extension
    }
}
?>
<div id="myelement">Hello</div>




Let me know if this works for you.
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am


Return to Plugins & Widgets

Who is online

Users browsing this forum: No registered users and 2 guests

cron