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.