PHP一直以來都是每個人自己寫自己的 Framework .....
基本上除了都是用 PHP 以外
更重要的是:.......
更重要的是:.....
同一個公司的同事寫的
竟然也不一樣
PHP程式設計師需要一個易學易用的Framework
PHP程式設計師需要能快速將概念化為實做
Web 2.0 的時代,不能慢吞吞的慢慢刻程式,建立架構
等你完成架構,開始寫程式,人家早就玩完了!!
ActiveRecord
No More SQL in Your Code!
post.php<?php
class Post extends AppModel{
var $name = 'Post';
var $validate = array(
'title' => VALID_NOT_EMPTY,
'content' => VALID_NOT_EMPTY,
);var $hasMany = array('Comment');var $hasAndBelongsToMany = array('Tag');?>
comment.php<?php
class Comment extends AppModel
{
var $name = 'Comment';
var $validate = array(
'name' => VALID_NOT_EMPTY,
'email' => VALID_EMAIL,
'content' => VALID_NOT_EMPTY,
'post_id' => VALID_NOT_EMPTY,
);
var $belongsTo = array('Post');
}
?>
tag.php
<?php
class Tag extends AppModel
{
var $name = 'Tag';
var $validate = array(
'name' => VALID_NOT_EMPTY,
);
var $hasAndBelongsToMany = array('Post');
}
?>
posts.php<?php
class PostsController extends AppController
{
//var $scaffold;
var $name = 'Posts';
var $helpers = array('Html', 'Form' );
function index() {
$this->Post->recursive = 0;
$this->set('posts', $this->Post->findAll());
}function view($id) {
$this->set('post', $this->Post->read(null, $id));
}
?>
index.thtml<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id'] ?></td>
<td><?php echo $post['Post']['title'] ?></td>
<td><?php echo $post['Post']['content'] ?></td>
<td><?php echo $post['Post']['created'] ?></td>
<td>
<?php echo $html->link('View','/posts/view/' . $post['Post']['id'])?>
<?php echo $html->link('Edit','/posts/edit/' . $post['Post']['id'])?>
<?php echo $html->link('Delete','/posts/delete/' . $post['Post']['id'], null, 'Are you sure you want to delete: id ' . $post['Post']['id'])?>
</td>
</tr>
<?php endforeach; ?>