eZ Community » Forums » Install & configuration » Custom fetch functions
expandshrink

Custom fetch functions

Custom fetch functions

Monday 13 August 2007 1:12:43 am - 8 replies

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))}

Monday 13 August 2007 1:46:07 am

Hello Christian,

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

Cheers,
Heath

Modified on Monday 13 August 2007 10:11:44 am by // Heath

Monday 13 August 2007 6:14:33 am

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

Modified on Tuesday 14 August 2007 5:06:45 am by Bruce Morrison

Monday 13 August 2007 5:36:52 pm

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?

Tuesday 14 August 2007 12:52:36 am

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 happy.gif Emoticon I guess I'll submit it as a contribution once I've worked it through.

Tuesday 14 August 2007 5:07:27 am

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

@Heath
Good to see my advice make it onto ezpedia.org blunk.gif Emoticon

Friday 24 August 2007 3:42:13 am

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)

Thursday 28 February 2008 6:33:13 pm

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

Thursday 28 February 2008 11: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

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from