Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created March 12, 2011 17:37
Show Gist options
  • Save uppfinnarjohnny/867392 to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/867392 to your computer and use it in GitHub Desktop.
Tok-simpel MVC-struktur
<?php
include('posts_model.php');
$posts = get_posts();
include('view.php');
<?php
function get_posts() {
$posts = array(
(object) array(
'title' => 'En titel',
'body' => 'Här är då brödtexten'
),
(object) array(
'title' => 'En till titel',
'body' => 'Och en till brödtext'
)
);
return $posts;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>MVC-exempel</title>
</head>
<body>
<h1>Ett MVC-exempel</h1>
<?php foreach($posts as $post): ?>
<div class="post">
<h2><?php echo $post->title; ?></h2>
<?php echo $post->body; ?>
</div>
<?php endforeach; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment