Trace:
Differences ¶
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
en:tutorial:using-dao [2007/01/13 21:37] – doubleface | en:tutorial:using-dao [2007/01/13 22:09] – doubleface | ||
---|---|---|---|
Line 12: | Line 12: | ||
In the DAO XML file, you can also define your own access methods to data, and jDao will generate the corresponding methods and requests in the DAO factory. | In the DAO XML file, you can also define your own access methods to data, and jDao will generate the corresponding methods and requests in the DAO factory. | ||
+ | |||
===== creating a first DAO ===== | ===== creating a first DAO ===== | ||
Line 48: | Line 49: | ||
This is a very simple content, and of course there are other attributes and tags to enrich it and customize it. For the moment, we will leave it there. | This is a very simple content, and of course there are other attributes and tags to enrich it and customize it. For the moment, we will leave it there. | ||
+ | |||
+ | |||
+ | ===== List the news ===== | ||
+ | |||
+ | We will now use this DAO to retrieve the list of news. We thus will request from jDao the factory of this DAO, and call its preset method findAll. With this intention, we use jDao::get() : | ||
+ | |||
+ | <code php> | ||
+ | $fact = jDao:: | ||
+ | $liste = $fact-> | ||
+ | </ | ||
+ | |||
+ | As parameter of jDao:: | ||
+ | |||
+ | Actually, this is not really a list, but a jDbResultSet, | ||
+ | |||
+ | Let's integrate it in our controller : | ||
+ | |||
+ | <code php> | ||
+ | function index() { | ||
+ | $rep = $this-> | ||
+ | $rep-> | ||
+ | $rep-> | ||
+ | |||
+ | $fact = jDao:: | ||
+ | $list = $fact-> | ||
+ | |||
+ | $rep-> | ||
+ | |||
+ | return $rep; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | As stated ealier, the body property of jResponseHtml is a jTpl object (template engine). We give the list to it in a " | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | {foreach $list as $news} | ||
+ | <tr> | ||
+ | < | ||
+ | </tr> | ||
+ | {/foreach} | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | You discover here the {foreach} template tag, which | ||
+ | Vous découvrez ici le tag de template {foreach}, which is exactly like the php foreach. To display some values, you only have to put the name of the template var after a $ and between {}. | ||
+ | |||
+ | The list returned by findAll is a list of record objects, as defined in the xml file. The have then the id_news, subject, text and news_date properties. | ||
+ | |||
+ | Display the page one more time : | ||
+ | |||
+ | | ||
+ | |||
+ | You should see the list of news. | ||
+ | |||
+ | |||
+ | |||
+ | ---- | ||
+ | * Next : [[en: | ||
+ | * Previous : [[en: | ||
+ | * [[en: |