How to pass variables via URL to tree nodes

Author Message

Erik Weinmaster

Friday 20 November 2009 9:12:48 am

To help clarify my question, I'll explain what I am attempting to do. I am creating an interface via eZ Publish to view and edit entries from an external database. In essence my company has an old database that they can't integrate into ezp due to size. What I have done until now is have a basic 'shell' tree node (by shell I mean a class that has only a title attribute), then I've found the code in kernel/classes/eznodeviewfunctions.php that sets the templates variables used by the front end. Here I added a call to my own class to get entries from an external database and set them into template variables. Whether or not this was a good idea doesn't matter due to time constraints.
Now, I am trying to add different views to one particular tree node. Basically I want a list of items to appear when the user clicks on the node in the content tree which the url will be '.../home/nodenamehere/'. Then, I want to link to the same page and view the details of whatever item the user clicked on because the url will be '.../home/nodenamehere/variable1/variable2/'.
How could this be done?

Bertrand Dunogier

Friday 20 November 2009 11:31:40 am

Don't take this the wrong way, but you're doing it wrong. Really.

eZ Publish provides you with everything you need to integrate external databases. It will require a little more setup work, but you will end up with a much better integration.

What you need is a custom module with custom views. A view consists of a PHP script where you... well, you do whatever you want/can do with PHP. You also have the option to render your HTML using the standard eZ Publish template engine. You could for instance have a "list" view that displays a list of records, a "details" one that shows details about a record, etc. Views can accept parameters, like details/foo or details/1.

You can read the basics here: http://ezpedia.org/en/ez/module

If you integrate your database using the eZ Publish persistent object API, you will also be able to use your objects from templates like you would have done with any eZ Publish object (nodes, objects, etc).

P.S. eZ Publish itself is built using this module/view mechanism. Just check the kernel folder for some code ;)

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Erik Weinmaster

Friday 20 November 2009 2:23:00 pm

Bertrand,
Thanks for the quick reply. I understand the concept of what you stated in your reply with setting up a module with multiple views. However, I am having a little trouble getting started with the definitions in the module.php file.

After reading what you said and the directions from the link you provided, I have a module.php file setup in the extensions directory. This is where I get stuck... How do I link up the module.php file to a specific node (which can be reference by the class_identifier). What I would like is to use this module when the user clicks on my specifically named node. Thus if this click came from the content tree then there will not be any additional parameters so a list will show, and if the user clicks on a list item inside the node then the page will link to the new module with parameters and the details will show.

Right now I've only reached the point of defining the $ViewList array. So I have something that looks like this:

$ViewList['list'] = array(
'script' => 'list_view.php'
);
$ViewList['details'] = array(
'script' => 'details_view.php',
'unordered_params' => array( 'var1' => 'Var1',
'var2' => 'Var2' )
);

Bertrand Dunogier

Saturday 21 November 2009 12:36:42 am

You don't link to module.php. module.php is the module definition file.

In your case, to access your list, you just need to create a link to modulename/list. If your module's name is "externaldb", just use something like this:

<a href={'externaldb/list'|ezurl}>External DB</a>

Now you can just override your node view templates like you probably already did and create these links. Does this help ?

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 10:36:04
Script start
Timing: Jan 18 2025 10:36:04
Module start 'layout'
Timing: Jan 18 2025 10:36:04
Module start 'content'
Timing: Jan 18 2025 10:36:05
Module end 'content'
Timing: Jan 18 2025 10:36:05
Script end

Main resources:

Total runtime0.7986 sec
Peak memory usage4,096.0000 KB
Database Queries61

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 588.0469152.6406
Module start 'layout' 0.00610.0034 740.687539.4766
Module start 'content' 0.00950.7879 780.1641558.3125
Module end 'content' 0.79740.0012 1,338.476616.1250
Script end 0.7986  1,354.6016 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4130160.0002
Check MTime0.00130.1652160.0001
Mysql Total
Database connection0.00080.104410.0008
Mysqli_queries0.740892.7667610.0121
Looping result0.00060.0770590.0000
Template Total0.769696.420.3848
Template load0.00230.288320.0012
Template processing0.767396.079820.3837
Template load and register function0.00020.030910.0002
states
state_id_array0.00100.122810.0010
state_identifier_array0.00120.144220.0006
Override
Cache load0.00180.2271340.0001
Sytem overhead
Fetch class attribute can translate value0.00070.085920.0003
Fetch class attribute name0.00280.355450.0006
XML
Image XML parsing0.00070.093320.0004
class_abstraction
Instantiating content class attribute0.00000.002160.0000
General
dbfile0.00080.1053160.0001
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 20
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs