プログラム用語

[text]変数 :データにつけるラベル[/text]
演算子
[text][/text]代入演算子 : = [text][/text]
[text][/text]文字列に関する演算子 : ”hollo” + “world”[text][/text]
[text][/text]
数値関する演算子 : + – * /
% は 余り
var x = 1;
x++ //x = x + 1;
x– //x = x – 1;
x +=5 // x = x + 5;
[text][/text]

オーバーライド

オブジェクト指向プログラミングにおいてオーバーライド (override)とは、スーパークラスで定義されたメソッドをサブクラスで定義しなおし、動作を上書きすることである。
http://ja.wikipedia.org/wiki/%E3%82%AA%E3%83%BC%E3%83%90%E3%83%BC%E3%83%A9%E3%82%A4%E3%83%89

コンストラクタ

オブジェクト指向のプログラムにおいてオブジェクトを生成するための手続き

http://ja.wikipedia.org/wiki/%E3%82%B3%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%BF%E3%83%BC

hasOneの一括保存

http://cakephp.jp/modules/newbb/viewtopic.php?topic_id=796&forum=6
[php]
public function add() {
if ($this->request->is(‘post’)) {
$this->User->create();
if (!empty($this->data)) {
$user = $this->User->save($this->data);
//if ($this->User->save($this->request->data)) {

// User が保存されたら、User_detail データに User の情報を追加し
// 保存します。
if (!empty($user)) {
// 新しく生成した User の ID は、
// $this->User->id にセットされます。
$this->User->UserDetail->data[‘UserDetail’][‘user_id’] = $this->User->id;

// User は User_detail と hasOne のアソシエーションで関連付いているので
// User モデルを通して Profile モデルにアクセスできます:
$this->User->UserDetail->save($this->data);
}
$this->Session->setFlash(
__(‘保存しました’, __(‘user’)),
‘alert’,
array(
‘plugin’ => ‘TwitterBootstrap’,
‘class’ => ‘alert-success’
)
);

$this->redirect(array(‘action’ => ‘index’));
} else {
$this->Session->setFlash(
__(‘保存失敗’, __(‘user’)),
‘alert’,
array(
‘plugin’ => ‘TwitterBootstrap’,
‘class’ => ‘alert-error’
)
);
}
}
$lectures = $this->User->Lecture->find(‘list’);
$prefectures = $this->User->Prefecture->find(‘list’);
$userDetails = $this->User->UserDetail->find(‘list’);
$numbers = $this->User->Number->find(‘list’);
$this->set(compact(‘lectures’, ‘prefectures’, ‘userDetails’,’numbers’));
debug($userDetails);
}
[/php]
[php]
public $hasOne = array(
‘UserDetail’ => array(
‘className’ => ‘UserDetail’,
‘foreignKey’ => ‘user_id’,
‘conditions’ => ”,
‘fields’ => ”,
‘order’ => ”
)
);[/php]

idを取るリンク

Controller
[php]
public function view($id = null) {
$this->Post->id = $id; //idを取る
$this->set(‘post’, $this->Post->read()); //あるIDのデータをフィールド情報+データで受け取る
}
[/php]

View
[php]
<ul>
<?php foreach ($posts as $post) : ?>
<li>
<?php
// debug($post);
// echo h($post[‘Post’][‘title’]);
//
echo $this->Html->link($post[‘Post’][‘title’],’/posts/view/’.$post[‘Post’][‘id’]); //idにリンクをはる
?>
</li>
<?php endforeach; ?>
</ul>[/php]

変数

[php]
public function index() {
$params = array(   //params変数の中身を書く
‘order’ => ‘modified desc’,
‘limit’ => 2
);
$this->set(‘posts’, $this->Post->find(‘all’, $params)); //params変数を呼び出し
$this->set(‘title_for_layout’, ‘記事一覧’);
}
[/php]

routes.php

/app/Config/routes.php
[php] Router::connect(‘/’, array(‘controller’ => ‘posts’, ‘action’ => ‘index’));
//どのコントローラのページをルートに表示させるか。postsページのindexページを表示させる
[/php]

foreach

Controller
[php]
<?php

class PostsController extends AppController {
public $helpers = array(‘Html’, ‘Form’); //ヘルパー使いますよ
public function index() {
$this->set(‘posts’, $this->Post->find(‘all’)); // posts変数をviewで使うよ Postのデータを全部取得するよ
}

}
[/php]

Viwe
[php]
<ul>
<?php foreach ($posts as $post) : ?> // foreachでぐるぐると取得するよ 
<li>
<?php
// debug($post);
echo h($post[‘Post’][‘title’]);
?>
</li>
<?php endforeach; ?> // foreachでぐるぐると取得の締め
</ul>
[/php]

findメソッド :CakePHP2.1

http://w.builwing.info/2012/05/16/cakephp2-1%E3%81%AEfind%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89/

[php]
find(‘all’, array(
‘conditions’ => array(‘Article.id’ => 1), ////検索条件の配列
‘fields’ => array(‘"User2"."id"’), ////フィールド名の配列
‘order’ => ‘Article.created’ => ‘desc’, //並び順を文字列または配列で指定
‘recursive’ => 2,
‘group’ => ‘type’
));
[/php]

Webメモ