Request for Help: Module Example/External PHP Script

Author Message

Alex Jones

Monday 07 July 2003 12:52:47 pm

Howdy, I am trying to understand proper module creation and how to use an external PHP script. Hopefully someone can help me out.

Could anyone take a couple of minutes and tell me step-by-step how I could create a module to automatically include some PHP in my templates? I have some solid PHP that I use to detect browser/platform combinations and write-out the proper navigation (contained in a separate file and included via require_once) for the combo. This needs to be included on every page of my site. How can I add this without rewriting the entire script? I assume it needs a module, if not what should I be trying to do?

One note, I have read the article entitled "How can I use my own php script inside eZp?" but it doesn't address my needs as far as I can tell.

Really, the best of all worlds would be a module that would allow me to include PHP as needed, routing around eZPublish's parser.

I truly appreciate the help!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Tuesday 08 July 2003 12:56:24 am

Alex,

There are many ways to use ez 3 to include your own php.

Modules allow the grouping of functions, operators and scripts under one area, ie content, shops, users and so on. Within modules you have your functions which retreive information using the fetch command, and operators allow an abitrary block of php code to be run.

If you have a lot of similar functionality to implement a module should be written. http://ez.no/sdk/ezutils/view/module_handling/ gives some explanation about to start one off.

For your browser code it seems an operator is maybe the best way to proceed. For example you could call your operator by using {$browser_id} in your template.

Look in the contributed code section at operators like:

http://ez.no/developer/ez_publish_3/contributions/ezipcountry_operator
http://ez.no/developer/ez_publish_3/contributions/glossary_operator

and see how they add operators to ez.

With this operator you could run your browser code, prepare the html, and return the output.

Start with this and then see if you need more.

Paul

Alex Jones

Tuesday 08 July 2003 6:29:31 am

Thanks Paul! As always you prove to be quite helpful. I will check out the two contributed operators you listed as a starting point to move forward.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Alex Jones

Tuesday 08 July 2003 8:45:02 am

Okay, as much as I hate to admit it, I'm stumped. While I am relatively experienced with PHP I'm still learning the OOP side of it, which in combination with the eZp learning curve is proving quite daunting. I have been studying the operators and looking through the documentation, but I just don't see how to take my existing code (which is object-oriented) and include it as an operator within a template.

I think I may be missing something basic as my experiments run into problems; usually displaying a variant of " Unknown template variable 'eZSniff' in namespace '' ".

If you don't mind could you write up a short list of the exact steps to create an operator starting from a blank file in the extensions directory and including the modifications to the site.ini and the template file? Perhaps a simple "hello world" PHP script that echoes"hello world" which is then included in the template. This would be immensely helpful.

I'm sure this is simple as the template itself doesn't require any logic, it just needs to call the PHP which does the browser detection and spits out the appropriate HTML.

If this is confusing, I apologize, but I'm rather confused myself. ;) Hopefully I will reach a deeper understanding soon so I can help answer questions like these.

Thanks!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Tuesday 08 July 2003 9:09:06 am

There is a learning curve here.

Well, the first step is to get operators working with your setup. Can you install one of the operators i pointed to? Try the ezipcountry one because it is very simple.

Once you have that working and have convinced yourself you know whats going on you can then link the same code to your own.

paul

Paul Forsyth

Tuesday 08 July 2003 9:29:37 am

just had a thought, the ezipcountry operator might not be that easy to install...

paul

Paul Borgermans

Tuesday 08 July 2003 10:07:06 am

And what about the operator wizard in 3.1? It's available from admin/setup/rad.

This gives you skeleton code with instructions for install.

--paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Paul Forsyth

Tuesday 08 July 2003 10:08:37 am

Last time i tried the rad tool it gave me the wrong code which i had to fix before it would work as intended. Haven't tried it since.

paul

steve walker

Wednesday 12 May 2004 10:25:14 am

Paul/Alex,

Was there any progress on this in terms of making a plain speak tutorial? I have been looking at:

http://www.ez.no/ez_publish/documentation/development/extensions/template_operator

http://www.ez.no/community/forum/setup_design/truncating_a_string

the first of which looks complete, but is still quite daunting. I used the RAD facility to create a eztruncate class - I have the code - but it doesnt have any instructions in it...

Is this a suck it and see situation?

Regards, Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Wednesday 12 May 2004 10:55:56 am

Sadly, I do not know of a good tutorial on this subject.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Thursday 13 May 2004 12:25:35 am

The forthcoming ez book has a tutorial on template creation:

http://www.amazon.co.uk/exec/obidos/ASIN/1904811019/ref=ase_vision01/026-8210527-9190009
and
http://www.packtpub.com/view_book/isbn/1904811019

paul

--
http://www.visionwt.com

Alex Jones

Thursday 13 May 2004 6:34:09 am

That's good to hear Paul! FYI, for those in the U.S., Amazon.com isn't carrying the book yet (sigh), but Barnes and Noble do list it: http://search.barnesandnoble.com/booksearch/isbninquiry.asp?ISBN=1904811019 and it should be available come May 28. I can't wait to get my hands on a copy!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

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