Login +

How To ? / Getting recordsets

Suppose the Model of the table article generated:

Controller:

public function action()
{    
    // Get sls XML
    $xml = $this->getXML();
       
    // Object
    $this->_generic->useModel("Article");
    $article = new Main_Article();
       
    // Fetch last articles
    $articles = $article->searchModels("article", array(), array(), array(), array(array("column" => "article_date", "order" => "desc")));
    $xml->startTag("articles");
    for($i=0 ; $i<$count=count($articles) ; $i++)
    {
        $xml->startTag("article");
        foreach($articles[$i] as $key => $value)
            $xml->addFullTag($key, $value, true);
        $xml->endTag("article");
    }
    $xml->endTag("articles");
    
    // Save sls XML updated
    $this->saveXML($xml);}
}

View:

<h1>Last articles</h1>
       
<div class="news">
    <xsl:for-each select="//View/article/article">
        <div class="article">
            <h2>
                <xsl:value-of select="article_title" /> -
Posted <xsl:value-of select="article_date" />
            </h2>
            <p>
                <xsl:value-of select="article_content" />
            </p>
        </div>
    </xsl:for-each>
</div>