Clover
1.0.0
三叶草是基于MVC的小型PHP框架。
<?php
class Home extends Controller {
public function __construct () {
$ this -> load_model ( ' Home_model ' );
}
public function index () {
$ result = $ this -> model -> get_posts ();
$ this -> load_view ( ' home ' , $ result );
}
}
?> <?php
class Home_model extends Model {
public function __construct () {
parent :: __construct ();
}
public function get_posts () {
return $ this -> db -> query ( " SELECT * FROM POST " );
}
}
?><! DOCTYPE html>
<html lang="en">
<head>
<meta charset=" UTF - 8 ">
<meta name="viewport" content="width=device-width, initial-scale= 1.0 ">
<meta http-equiv="X- UA -Compatible" content="ie=edge">
<title>Home</title>
</head>
<body>
<h1>This is Home.</h1>
<?php foreach ( $ params as $ value): ?>
<h1> <?php echo $ value['post_title']; ?> </h1>
<p> <?php echo $ value['post_content']; ?> </p>
<?php endforeach ; ?>
</body>
</html>