ez.no / exponential / documentation / development / extensions / module / module tutorial (part 1)
In this example we make a module named "mymodule".
"mymodule" has 1 view called "list".
We have one template where we use fetch to list all our data from our database table called "mytable".
In your exponential directory there is "extension"-folder (If not, create one).
Inside that folder we make folder for our module "mymodule".
Inside that folder we make folder structure like this:
(/extension/mymodule)/modules/mymodule (extension/mymodule)/settings
Then we create folder under the "standard" design.
/design/standard/templates/mymodule/
Inside folder: extension/mymodule/modules/mymodule,
we put all the files expect the "list.tpl" and "module.ini.append" -files.
Inside folder: extension/mymodule/settings,
we put the module.ini.append file.
Inside folder: /design/standard/templates/mymodule/,
we will put the list.tpl -file.
[ModuleSettings] ExtensionRepositories[]=mymodule
We create a table named "mytable" to ez database and make 2 cells, "id" and "name".
We add some data to the table:
id name
1 First row
2 Second row
$Module = array( 'name' => 'mymodule' ); $ViewList = array(); $ViewList['list'] = array( 'script' => 'list.php', "unordered_params" => array( "offset" => "Offset" ) );
What happens here is that we make a view "list" for the module,
witch points to file "list.php" and we send parameter "Offset" to it.
$Module =& $Params['Module']; $Offset = $Params['Offset']; if ( !is_numeric( $Offset ) ) $Offset = 0; $viewParameters = array( 'offset' => $Offset ); include_once( 'kernel/common/template.php' ); $tpl =& templateInit(); $tpl->setVariable( 'view_parameters', $viewParameters ); $Result = array(); $Result['content'] = $tpl->fetch( "design:mymodule/list.tpl" ); $Result['path'] = array( array( 'url' => false, 'text' => 'My Module' ), array( 'url' => false, 'text' => 'List' ) );
In here we receive the parameters from module.php and send them forward to list.tpl with template "setVariable" function.
Then we load the list.tpl to screen ($tpl->fetch( "design:mymodule/list.tpl" );
)...
{let data_limit=10 data_list=fetch('mymodule','list',hash(offset,$view_parameters.offset,limit,$data_limit))} All Data {section name=DATA loop=$data_list sequence=array(bglight,bgdark)} {$:item.id}{$:item.name} {/section} {/let}
Actually we don't need that "data_limit" and "hash(offset...)" thing in our example now,
but it's there just to show how the Offset parameter goes around the files...
Hint: {$:item.xxx} is the name of our database tables cell...
To archieve in this we need 2 files: mymodulefunctioncollection.php and function_definition.php.
First, function_definition.php
$FunctionList = array(); $FunctionList['list'] = array( 'name' => 'list', 'operation_types' => array( 'read' ), 'call_method' => array( 'include_file' => 'extension/mymodule/modules/mymodule/mymodulefunctioncollection.php', 'class' => 'MyModuleFunctionCollection', 'method' => 'fetchList' ), 'parameter_type' => 'standard', 'parameters' => array( array( 'name' => 'offset', 'required' => false, 'default' => false ), array( 'name' => 'limit', 'required' => false, 'default' => false ) ) );
Second, mymodulefunctioncollection.php:
include_once( 'extension/mymodule/modules/mymodule/mymodule.php' ); class MyModuleFunctionCollection { function MyModuleFunctionCollection() { } function &fetchList( $offset, $limit ) { $parameters = array( 'offset' => $offset, 'limit' => $limit ); $lista =& Mymodule::fetchListFromDB( $parameters ); return array( 'result' => &$lista ); } }
Third, mymodule.php:
This file is going to keep and handle all of our main functions.
include_once( 'kernel/classes/ezpersistentobject.php' ); class Mymodule extends eZPersistentObject { function Mymodule( $row ) { $this->eZPersistentObject( $row ); } function &definition() { return array( 'fields' => array( 'id' => array( 'name' => 'id', 'datatype' => 'integer', 'default' => 0, 'required' => true ), 'name' => array( 'name' => 'name', 'datatype' => 'string', 'default' => '', 'required' => true ) ), 'keys' => array( 'id' ), 'increment_key' => 'id', 'class_name' => 'mymodule', 'name' => 'mytable' ); } function &fetchListFromDB( $parameters = array() ) { return Mymodule::handleList( $parameters, false ); } function &handleList( $parameters = array(), $asCount = false ) { $parameters = array_merge( array( 'as_object' => true, 'offset' => false, 'limit' => false ), $parameters ); $asObject = $parameters['as_object']; $offset = $parameters['offset']; $limit = $parameters['limit']; $limitArray = null; if ( !$asCount and $offset !== false and $limit !== false ) $limitArray = array( 'offset' => $offset, 'length' => $limit ); return eZPersistentObject::fetchObjectList( Mymodule::definition(), null, null, null, $limitArray, $asObject ); } }
Now we just login to our admin site and goto url: /mymodule/list.
We see our list.tpl showing the 2 variables from the database... (Hopefully)
In part 2 we will add few more views (create/edit) and another fetch function.
Log in or create a user account to comment.
Comments
Part 2
Hans-Henry Jakobsen
Friday 06 January 2006 12:41:31 am
variable_params in module definition
Kristof Coomans
Tuesday 01 November 2005 11:22:26 am
Multiple modules in one extension
Kristof Coomans
Tuesday 01 November 2005 11:21:40 am
Some information about module policies
Kristof Coomans
Tuesday 04 October 2005 12:41:23 pm
The requested page could not be displayed
abdalla chakik
Wednesday 13 July 2005 8:30:25 am
http://127.0.0.1/index.php/cciat_admin/mymodule/list.php
http://127.0.0.1/index.php/cciat_...n/mymodule/modules/mymodule/list.php
but he told me page could not be displayed...
why???
i creat a folder in extension called mymodule an i put insidt it 2 folders:modules and settings,and i put in the modules folder named mymodule and i put in mymodule folder 5 files.
function_definition.php,list.php,module.php,mymodule.php,mymodulefunctioncollection.php.and i put in the designe folder all you said.why i have that problem??and thx all.
Part 2
Nuffstress Group
Wednesday 08 June 2005 4:25:55 pm
If you have "Undefined module: mymodule" in debug mode....
Olivier Pierret
Thursday 04 November 2004 2:39:45 pm
ExtensionRepositories[]=mymodule
in /exponential/settings/modules.ini .
In my case, the exponential does not seem to take module.ini.append file into account. Any thoughts ?
Changing your extension or module name without having to change code.
Kristof Coomans
Friday 30 April 2004 10:10:14 am
By using the PHP function get_defined_vars( ) in function_definition.php and operation_definition.php, and printing the resulting array, I found out that you can access the module's path by using $path, and the modules name by using $this->ModuleName in both files.
Example code:
$OperationList['operation']= array
(
'name' => 'operation',
'default_call_method' => array
(
'include_file' => $path . '/' . $this->ModuleName . '/operationcollection.php',
'class' => 'OperationCollection'
),
...
If you code the paths like in this example, you won't have to change any code if you ever want to change the module name or if you put your module in another extension.
mymodule
Kristof Coomans
Thursday 18 March 2004 4:13:26 pm
The module.ini.append file would then look like this:
[ModuleSettings]
ExtensionRepositories[]=myextension
extension templates
Dominik Pich
Friday 13 February 2004 12:30:03 pm
add a design.ini.append next to your module.ini.append
with the content:
[ExtensionSettings]
DesignExtensions[]=mymodule
Then put the tpl(s) here:
/extension/mymodule/design/standard/templates/mymodule
If module works but no results appear try this:
New User
Thursday 02 October 2003 5:18:53 pm
No template could be loaded for "mymodule/list.tpl" using resource "design'
And you are certain that file exists, I would try manually deleting all cache in that design's /var folder and any ini cache and codepage cache. I'm not certain which deletion will get you right, as I did all three and it began to work. At any rate, these symptoms above indicate something was cached that you need renewed.
ExtensionRepositories...
Ibrahim Khachab
Friday 08 August 2003 8:11:00 am
I tried many ways to activate this module:
- You may activate it for one site (mysite) and in this case I found that the module is activated either by adding
ExtensionRepositories[]=mymodule
to the [ModuleSettings] section in the file
/settings/siteacces/mysite/module.ini.append
or by adding
ActiveAccessExtensions[]=mymodule
to the [ExtensionSettings] section in the file
/settings/siteacces/mysite/site.ini.append
- You may activate it for all sites (remember to create the table in all databases) and in this case the module is activated either by adding
ActiveExtensions[]=mymodule ("ActiveExtensions" and not "ActiveAccessExtensions")
to the [ExtensionSettings] section in the file
/settings/override/site.ini.append
I hope this will help
ExtensionRepositories...
Selmah Maxim
Monday 28 July 2003 5:32:24 pm
am using 3.2 r2881
ExtensionRepositories...
Jerry Jalava
Monday 28 July 2003 5:24:03 pm
Jerry
Module tutorial (Part 1)
Selmah Maxim
Monday 28 July 2003 11:58:30 am
#ExtensionRepositories[]