開発メモ

開発用のメモです。

cakephp コントローラー ページ管理

<?php
class UsersController extends AppController {
    public $paginate = array (
            'limit' => 20,
            'order' => 'User.id'
             
    );
    public function index() {
        if (isset ( $this->request->data ["Control"] )) {
            $this->redirectAction ( $this->request->data ["Control"] );
        }
        
        $options = array ();
        // $this->request->list = $this->User->find ( "all" );
        $this->request->list = $this->paginate ( "User" );
    }
    public function detile($id = -1) {
        $this->render ( "edit" );
    }
    public function create() {
        if ($this->request->data ( "Control" ) == 'cancel') {
            $this->redirectAction ( "index" );
            // exit
        }
        if ($this->request->data ( "Control" ) == 'create') {
            if ($this->User->save ( $this->request->data )) {
                $this->Session->setFlash ( "登録が完了しました。" );
                $this->redirectAction ( "index" );
            } else {
                $this->Session->setFlash ( "登録失敗です。" );
            }
        } else {
            $this->request->data ["User"] = array (
                    "id" => null,
                    "name" => null,
                    "account" => null,
                    "mail_address" => null,
                    "login_password" => null,
                    "fail_count" => null,
                    "last_login" => null,
                    "created" => null,
                    "modified" => null 
            );
            // $this->request->data["User"] = new User();
        }
        $this->render ( "edit" );
    }
    public function edit($id = 0) {
        if ($this->request->data ( "Control" ) == 'modify') {
            if ($this->User->save ( $this->request->data )) {
                $this->Session->setFlash ( "更新が完了しました。" );
                $this->redirectAction ( "index" );
            } else {
                $this->Session->setFlash ( "更新失敗です。" );
            }
        } else {
            $this->request->data = $this->User->findById ( $id );
        }
        // $this->render ( "edit" );
    }
}
Twitter: @asahina_alice