Custom fetch functions

Author Message

Christian Johansen

Sunday 12 August 2007 4:12:43 pm

Is there any documentation around on how I could make my own fetch function in an extension or something like that? I want to be able to do something like this in my templates:

{def $collection=fetch(mystuff, myfetch, hash(some, params))}

Heath

Sunday 12 August 2007 4:46:07 pm

Hello Christian,

<i>http://ezpedia.org/wiki/en/ez/custom_fetch</i>

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Bruce Morrison

Sunday 12 August 2007 9:14:33 pm

Hi Christian

I'm not sure about this advice from the previous post.

While you prolly can create your own custom fetch functions by creating your own php class which you can use with a custom template operator or module. It would be faster (re: development time) to simply create a custom template operator which does what you wish.I would suggest you instead consider creating your own template operators to meet your needs or perhaps use the wrap operator which is even faster to get started with :)

While you probably could use an template operator it's not the right "tool" and it isn't too hard to setup a fetch.

Assuming you already have a module mystuff setup the following is all you need to do.

In extension/mystuff/modules/mystuff/function_definition.php

<?php
$FunctionList = array();
$FunctionList['MyFetch'] = array( 'name' => 'myfetch',
                                'operation_types' => array( 'read' ),
                                'call_method' => array( 'include_file' => 'extension/mystuff/modules/mystuff/mystufffunctioncollection.php',
                                'class' => 'MyStuffFunctionCollection',
                                'method' => 'fetchMyFetch' ),
                                'parameter_type' => 'standard',
                                'parameters' => array(array('name'    => 'some',
                                                            'type'    => 'integer',
                                                            'required' => true,
                                                            'default' => -1
                                                          ),
                                                      array('name'    => 'params',
                                                            'type'    => 'string',
                                                            'required' => true,
                                                            'default' => ''
                                                          )

                                                )
);
?>

and in extension/mystuff/modules/mystuff/mystufffunctioncollection.php

<?php
class MyStuffFunctionCollection
{

  function MyStuffFunctionCollection()
  {
  }

  function &fetchMyFetch($some,$params)
  {
    $result =& retrieve data here
    return array( 'result' => $result );
  }
}
?>

HTH

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Christian Johansen

Monday 13 August 2007 8:36:52 am

Thanks alot! One more question: My extension is going to fetch some data from an xml feed. It's hard to find documentation on PHP4s XML functionality as PHP 5 has taken over completely. What's the preferred way of working with XML in eZP modules? I just need to load an external XML resource and fetch some nodes using xpath queries or something like that. Can I use eZs library? Or the php extension? Can anyone point me to (php4 relevant) documentation?

Christian Johansen

Monday 13 August 2007 3:52:36 pm

I got it working, thanks for all your hints! I now have a working

{def $tracks=fetch(audioscrobbler, recent_tracks, hash(user, 'cromlech'))}

that fetches data from the AudioScrobbler services (http://www.audioscrobbler.net/data/webservices/) / www.last.fm, very cool :) I guess I'll submit it as a contribution once I've worked it through.

Bruce Morrison

Monday 13 August 2007 8:07:27 pm

@Christian
Glad to be of assistance! Looking forward to the contribution.

@Heath
Good to see my advice make it onto ezpedia.org ;)

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Christian Johansen

Thursday 23 August 2007 6:42:13 pm

It took some time to finish all the documentation (rather gathering the will to do so...), but I did it: http://ez.no/community/contribs/template_plugins/ezaudioscrobbler

Another thanks to you Bruce!

(This post is just for future reference, wanted to link up the contrib here, in case someone search it up later)

Christophe Campan

Thursday 28 February 2008 9:33:13 am

Help,

I'm now working on the ez version 4.0. I won't to make a custom fetch.
But I have read on a forum, that the way to do it is different on the new
ez version 4.0.

Someone are able to help me?

Thanks

Bruce Morrison

Thursday 28 February 2008 2:23:39 pm

Hi Christophe

eZ4.0 is essentially a port of eZ 3 to PHP 5. The method of creating a custom fetch is the same.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

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