List Info

Thread: DB_DataObject_Iterator




DB_DataObject_Iterator
user name
2007-05-29 10:01:49
Hi everypearbody !
I've been using DB_dataObject in several sites now, most of
them  
using a templating system.
So I found it helpful to implement an Iterator to DBDO so
that I can  
use a regular loop to fetch my DBDO results in the
template.
You can find the php file in a compressed file here :
http:
//demental.info/DB_DataObject_Iterator.php

To use it you need MDB2 (does not work with DB), and PHP5
(for  
Iterator implementation).
This is an example DB_DataObject configuration to use it :

$options = array (  'database' => DB_URI,
                     'schema_location' =>
'your/schema/path',
                     'class_location' =>
'your/DOclasses/path',
                     'require_prefix' => 'DataObjects/',
                     'class_prefix' => 'DataObjects_',
                     'extends'
=>'DB_DataObject_Iterator',
                    
'extends_location'=>'path/to/DB/DataObject/ 
Iterator.php',
                     'db_driver'=>'MDB2',
                 );

And a short usage example using trivial articles and
comments tables  
(e.g. in a blog) :
<?php
$art = DB_DataObject::factory('articles');
$art->find();
// then you can for example assign it to a Smarty instance
:
$smarty->assign_by_ref('articles',$art);
?>

In a smarty template (or whatever templating engine), use it
with  
foreach :

{foreach from=$articles item=article}
<div id="article_{$article->id}">
<h3>{$article->title}</h3>
<p>{$article->body}</p>
<hr />
<dl><dt>Comments :</dt>
{foreach from=$articles->getComments() item=comment}
<dd>
	<span>From {$comment->author} on
{$comment->date}</span>
	{$comment->body}
</dd>
{/foreach}
</dl>
</div>
{/foreach}

Let me know if you find this stuff interesting !

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re: DB_DataObject_Iterator
user name
2007-05-29 10:18:48
> Hi everypearbody !
> I've been using DB_dataObject in several sites now,
most of them  using a 
> templating system.
> So I found it helpful to implement an Iterator to DBDO
so that I can  use 
> a regular loop to fetch my DBDO results in the
template.
> You can find the php file in a compressed file here :
> http:
//demental.info/DB_DataObject_Iterator.php
>
> To use it you need MDB2 (does not work with DB), and
PHP5 (for  Iterator 
> implementation).
> This is an example DB_DataObject configuration to use
it :
>
> $options = array (  'database' => DB_URI,
>                     'schema_location' =>
'your/schema/path',
>                     'class_location' =>
'your/DOclasses/path',
>                     'require_prefix' =>
'DataObjects/',
>                     'class_prefix' =>
'DataObjects_',
>                     'extends'
=>'DB_DataObject_Iterator',
>                    
'extends_location'=>'path/to/DB/DataObject/ 
> Iterator.php',
>                     'db_driver'=>'MDB2',
>                 );
>
> And a short usage example using trivial articles and
comments tables 
> (e.g. in a blog) :
> <?php
> $art = DB_DataObject::factory('articles');
> $art->find();
> // then you can for example assign it to a Smarty
instance :
> $smarty->assign_by_ref('articles',$art);
> ?>
>
> In a smarty template (or whatever templating engine),
use it with  foreach 
> :
>
> {foreach from=$articles item=article}
> <div id="article_{$article->id}">
> <h3>{$article->title}</h3>
> <p>{$article->body}</p>
> <hr />
> <dl><dt>Comments :</dt>
> {foreach from=$articles->getComments()
item=comment}
> <dd>
> <span>From {$comment->author} on
{$comment->date}</span>
> {$comment->body}
> </dd>
> {/foreach}
> </dl>
> </div>
> {/foreach}
>
> Let me know if you find this stuff interesting !

Sounds really interresting, but unfortunately your link
doesn't seem to 
work?

Met vriendelijke groet,
Cipriano Groenendal
-- 
  Transip BV | http://www.transip.nl/
  Hoogwaardige Innovatie | Aangename Zekerheid

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


Re: DB_DataObject_Iterator
user name
2007-05-29 12:16:54
Oops sorry this is not a php file, this is the right link :
>> http:
//demental.info/DB_DataObject_Iterator.tgz

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )