Hello peoplez of etomite,
I need to integrate an existing class in an etomatized site.
I dont even know where to begin trying this.
Is this possible at all/
How should I start?
cheerz,
v
using existing classes
Started by
vampke
, Apr 21 2011 07:36 PM
4 replies to this topic
#1
Posted 21 April 2011 - 07:36 PM
#2
Posted 21 April 2011 - 09:53 PM
More information would be helpful... What features does the new class provide...???
There are several ways to use additional classes within Etomite... The simplest way is to just use an include and then instantiate an iteration of the class in stand-alone mode... Another way would be to add "extends etomite" into the class name which "should" add the class functions to the Etomite object...
If you look at the bottom of the Etomite parser, index.php, you will see a line that includes my formClass class... To use it you would add the following lines into a snippet...
There are several ways to use additional classes within Etomite... The simplest way is to just use an include and then instantiate an iteration of the class in stand-alone mode... Another way would be to add "extends etomite" into the class name which "should" add the class functions to the Etomite object...
If you look at the bottom of the Etomite parser, index.php, you will see a line that includes my formClass class... To use it you would add the following lines into a snippet...
$f = new formClass;
#3
Posted 22 April 2011 - 08:48 AM
Thanks for your quick reply Ralph, I am puzzled by what you mean with :
What do you mean with 'stand-alone mode'?
This looks like a smooth way of doing it, however, if possible I would prefer not to touch the etomite core files.
I am afraid things will break if ever there should be a new update of etomite (wink-wink
)
Include in what? index.php?The simplest way is to just use an include and then instantiate an iteration of the class in stand-alone mode...
What do you mean with 'stand-alone mode'?
Another way would be to add "extends etomite" into the class name which "should" add the class functions to the Etomite object...
This looks like a smooth way of doing it, however, if possible I would prefer not to touch the etomite core files.
I am afraid things will break if ever there should be a new update of etomite (wink-wink
#4
Posted 22 April 2011 - 03:16 PM
Here is a simple example... The first block of code is the stand-alone class file which can be called from within a snippet for this example which is the most common method of using an external stand-alone class... The second code block is the snippet that includes and uses the class... By placing the snippet call [!test_class!] in a document or in a page template you will see the resulting code rendered by the snippet and class...
Now, this is a very simple example... If you want to use the class globally within Etomite then you can either add the include into the parser, as stated earlier, or you can use a separate snippet call within the <head> section of your page template to do a single include and then you could use the class from within multiple snippets or with repeated calls to the same snippet... To do that you might put something like the following in the snippet called from the <head>...
From there you can use the class anywhere within Etomite by referencing the $t-> class object just as you reference the $etomite-> class object... To do this you would add the [!include_test_class!] snippet call in the page templates <head> section and then omit the include related code from any snippets making calls to the class...
Hope this helps...
<?php
// test_class.php
class test_class
{
public $testvar1;
function __construct()
{
$this->testvar1 = "<p>Class Instantiated</p>";
}
function func1($text)
{
return "<p><b>{$text}</b></p>";
}
}
?>// Snippet:: test_class
$classPath = "relative_path_to_the_class"; // Example: "./manager/includes/"
include($classPath . "test_class.php");
$t = new test_class;
$output .= $t->testvar1;
$output .= $t->func1("This is a sample bold paragraph of text.");
return $output;Now, this is a very simple example... If you want to use the class globally within Etomite then you can either add the include into the parser, as stated earlier, or you can use a separate snippet call within the <head> section of your page template to do a single include and then you could use the class from within multiple snippets or with repeated calls to the same snippet... To do that you might put something like the following in the snippet called from the <head>...
// include_test_class snippet $classPath = "./manager/includes/"; include($classPath . "test_class.php"); $t = new test_class; // optionally instantiate the class at load time
From there you can use the class anywhere within Etomite by referencing the $t-> class object just as you reference the $etomite-> class object... To do this you would add the [!include_test_class!] snippet call in the page templates <head> section and then omit the include related code from any snippets making calls to the class...
Hope this helps...
#5
Posted 27 April 2011 - 08:33 AM
thanks ralph, good tutorial, will definitely look into this
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











