Created
January 3, 2012 05:15
-
-
Save hirak/1553616 to your computer and use it in GitHub Desktop.
Zend_Db_Tableをもっと手軽に使う(概要編) #ZFhimekuri ref: http://qiita.com/items/1539
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//常にZend_Db_Tableを作成するところから開始します。 | |
$posts = AR('posts'); | |
//テーブルクラスにデータを検索してもらったり | |
$latestPost = $posts->find(1)->current(); | |
//テーブルクラスに新しいRowデータの雛形を作ってもらったり | |
$newpost = $posts->createRow(); | |
$newpost->title = '新しいポスト'; | |
$newpost->text = '新しい記事だよー'; | |
$newpost->save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//主キーでの検索 | |
list($post) = AR('posts')->find(1); | |
//もしくは | |
$post = AR('posts')->find(1)->current(); | |
var_dump($post->toArray()); | |
//$postはそのまま配列風アクセスやオブジェクトアクセスが可能 | |
echo $post->name, "\t", $post['text'], "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//複雑な検索 | |
// ORDER BY created DESC LIMIT 1 で最新のPOSTを取得する | |
$latestPost = $posts->fetchRow(null, 'created DESC'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
list($post) = $posts->find(1); | |
$post->title = '修正したよ'; | |
$post->text = '修正した記事だよー'; | |
$post->save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$newPost = $posts->createRow(); | |
$newPost->name = '新しい記事だよー'; | |
$newPost->text = '新しい記事だよー'; | |
$newPost->save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
list($post) = $posts->find(1); | |
$post->delete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment