Created
June 26, 2011 16:03
-
-
Save nissuk/1047734 to your computer and use it in GitHub Desktop.
CakePHP 1.3: Modelを使用しないControllerでページネーションを行う単純な例
This file contains hidden or 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 | |
// {APP}/controllers/exapmle_controller.php | |
class ExampleController extends AppController { | |
var $name = 'Example'; | |
var $uses = null; | |
function index() { | |
// 1. ClassRegistryでUserモデルを生成します。 | |
$User = ClassRegistry::init('User'); | |
// 2. ページネーションの設定を行います。 | |
$this->paginate = array( | |
'limit' => 5, | |
'order' => 'User.id' | |
); | |
// 3. viewにデータを設定します。 | |
$this->set('users', $this->paginate($User)); | |
} | |
} |
This file contains hidden or 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
<!-- {APP}/views/example/index.ctp --> | |
<table> | |
<?php foreach($users as $user): ?> | |
<tr> | |
<td><?php echo h($user['User']['username']) ?></td> | |
</tr> | |
<?php endforeach ?> | |
</table> | |
<?php echo $this->Paginator->prev('< 前') ?> | |
<?php echo $this->Paginator->numbers(array( | |
'separator' => ' ' | |
)) ?> | |
<?php echo $this->Paginator->next('次 >') ?> |
This file contains hidden or 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
DROP TABLE IF EXISTS users; | |
CREATE TABLE users ( | |
id INT UNSIGNED AUTO_INCREMENT COMMENT "内部ID", | |
username VARCHAR(255) NOT NULL COMMENT "ユーザー名", | |
-- password VARCHAR(255) NOT NULL COMMENT "パスワード(sha1)", | |
PRIMARY KEY (id), | |
UNIQUE (username) | |
) Engine = InnoDB COMMENT = "ユーザー"; | |
INSERT INTO users(id, username) VALUES | |
(1, 'ne'), | |
(2, 'ushi'), | |
(3, 'tora'), | |
(4, 'u'), | |
(5, 'tatsu'), | |
(6, 'mi'), | |
(7, 'uma'), | |
(8, 'hitsuji'), | |
(9, 'saru'), | |
(10, 'tori'), | |
(11, 'inu'), | |
(12, 'i') | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment