Skip to content

Instantly share code, notes, and snippets.

@rakotomandimby
Created October 29, 2012 10:15
Show Gist options
  • Save rakotomandimby/3972754 to your computer and use it in GitHub Desktop.
Save rakotomandimby/3972754 to your computer and use it in GitHub Desktop.
<?php
class ArticleModel
{
public static function getArticleIds()
{
$xml = new XMLReader();
$tmp = $xml->open('encheres.xml');
while($xml->read())
{
if(('item' == $xml->name) && ($xml->nodeType == XMLReader::ELEMENT))
{
$result[]=$xml->getAttribute('id');
}
}
return $result;
}
}
<?php
class ArticleView
{
public function renderArticleIdList($article_id_array)
{
$result = '<html><head></head><body>';
$result .= '<ul>';
foreach($article_id_array as $un_id)
{
$result .= '<li><a href="?article='.$un_id.'">'.$un_id.'</a></li>';
}
$result .= '</ul>';
$result .= '</body></html>';
return $result;
}
}
<?php
require_once('Model/ArticleModel.php');
require_once('View/ArticleView.php');
if($_REQUEST['q'] == 'liste-articles')
{
$article_id_array=ArticleModel::getArticleIds();
$view = new ArticleView();
$output = $view->renderArticleIdList($article_id_array);
print $output;
}
else
{print 'mauvais paramètres';}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment