CREATE TABLE users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50),
password VARCHAR(50),
role VARCHAR(20),
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);
CREATE TABLE users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50),
password VARCHAR(50),
role VARCHAR(20),
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);
‘value’ => array(‘0’, 3)
引用元: CakePHPを用いて複数のチェックボックスの値をサーバサイドで取得する:東京ウェブ制作ブロマガ:東京ウェブ制作チャンネル(大和賢一郎) – ニコニコチャンネル:生活.
[php]
//コントローラー
public function add() {
if ($this->request->is(‘post’)) {
if($this->request->data[‘Lecture’][‘name’] == false){
//対象データがなかった処理
array(‘Lecture’ => array(
‘name’ => ‘test’
));
}
if ($this->request->data[‘Lecture’][‘name’] == true) {
//対象データがあった処理
$this->request->data[‘Lecture’][‘name’] = implode( ‘,’, $this->data[‘Lecture’][‘name’]); //カンマで区切るよ
}
$this->Lecture->create();
if ($this->Lecture->save($this->request->data)) {
$this->Session->setFlash(__(‘The lecture has been saved.’));
return $this->redirect(array(‘action’ => ‘index’));
} else {
$this->Session->setFlash(__(‘The lecture could not be saved. Please, try again.’));
}
}
$numbers = $this->Lecture->Number->find(‘list’);
$this->set(compact(‘numbers’));
}
[/php]
[php]
//view
$select1 = array(‘test’,’test1′);
echo $this->Form->input( ‘name’, array(
‘type’ => ‘select’,
‘multiple’=> ‘checkbox’,
‘options’ => $select1,
//’selected’ => $selected // 規定値は、valueを配列にしたもの
));
[/php]
[php]
//editコントローラー
$test= $this->Lecture->find(‘first’, array(
‘conditions’ => array(‘Lecture.id’ => $id),
‘fields’ => array(‘Lecture.name’), //フィールド名の配列
));
$this->set( ‘selected’, explode( ‘,’, $this->$test[‘Lecture’][‘name’]));
[/php]
[php]
//view editコントローラー
$select1 = array(‘test’,’test1′);
echo $this->Form->input( ‘name’, array(
‘type’ => ‘select’,
‘multiple’=> ‘checkbox’,
‘options’ => $select1,
‘selected’ => $selected // 規定値は、valueを配列にしたもの ここね
));
[/php]
参考:http://kwski.net/cakephp-2-x/1088/
//独自バリデーションルール
public function checkOnly($check){
//チェックしたいルールを書く
if (!empty($this->data[‘Brunch’][‘id’])){
//存在するか確認
$count = $this->find(‘count’, array(‘conditions’ => array(
‘brunch_name’ => $check[‘brunch_name’],
‘company_id’ => $this->data[‘Brunch’][‘company_id’],
‘NOT’ => array(‘Brunch.id’ => $this->data[‘Brunch’][‘id’])
)));
//1件でもあればfalseを返す
return $count == 0;
}else{
//新規の場合
//存在するか確認
$count = $this->find(‘count’, array(‘conditions’ => array(
$this->set( ‘select1’, $this->Prefecture->find( ‘list’, array(
‘fields’ => array( ‘id’, ‘prefecture’)
public function beforeFilter(){
$this->set(‘userSession’, $this->Auth->user());
}
acl_add