[やりたいこと]
・(取得したメッセージログをviewで表示するために)
test_tableというテーブルから取得した全てのデータからmessageのみを取り出したい
[実行]
PHP
1 2 // テーブル情報 3 protected static $_table_name = 'test_tab'; 4 protected static $_properties = [ 5 'id', 6 'message' 7 ]; 8 public function message_log() 9 { 10 // テーブル情報をすべて取得 11 $message_log = $this->find('all'); 12 13 // ここで出力したいデータの加工をする 14 // 下記のやり方だと一番最後のレコードしか取得できない 15 // foreach($test_table as $me) 16 // { 17 // $message = $me['message']; 18 // } 19 // $datas = array 20 // ( 21 // 'message' => $message, 22 // ); 23 24 return $message_log; 25 26 } 27 28
[実行結果]
print_r(message_log);
Array ( [1] => Orm_message Object ( [_is_new:protected] => [_frozen:protected] => [_data:protected] => Array ( [id] => 1 [message] => message001 ) [_custom_data:protected] => Array ( ) [_original:protected] => Array ( [id] => 1 [message] => message001 ) [_data_relations:protected] => Array ( ) [_original_relations:protected] => Array ( ) [_reset_relations:protected] => Array ( ) [_view:protected] => [_iterable:protected] => Array ( ) ) [2] => Orm_message Object ( [_is_new:protected] => [_frozen:protected] => [_data:protected] => Array ( [id] => 2 [message] => message002 ) [_custom_data:protected] => Array ( ) [_original:protected] => Array ( [id] => 2 [message] => message002 ) [_data_relations:protected] => Array ( ) [_original_relations:protected] => Array ( ) [_reset_relations:protected] => Array ( ) [_view:protected] => [_iterable:protected] => Array ( ) ) [3] => Orm_message Object ( [_is_new:protected] => [_frozen:protected] => [_data:protected] => Array ( [id] => 3 [message] => message003 ) [_custom_data:protected] => Array ( ) [_original:protected] => Array ( [id] => 3 [message] => message003 ) [_data_relations:protected] => Array ( ) [_original_relations:protected] => Array ( ) [_reset_relations:protected] => Array ( ) [_view:protected] => [_iterable:protected] => Array ( ) ) )
要はSELECT message FROM test_table;
と同じ結果です。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/19 00:37
2016/02/19 00:49
2016/02/19 13:09