Skip to content

Instantly share code, notes, and snippets.

<?php
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form');
function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
<div class="users index">
<h2><?php __('Users');?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
<div class="users view">
<h2><?php __('User');?></h2>
<dl><?php $i = 0; $class = ' class="altrow"';?>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $user['User']['id']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Username'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<div class="users form">
<?php echo $form->create('User');?>
<fieldset>
<legend><?php __('Add User');?></legend>
<?php
echo $form->input('username');
echo $form->input('password');
?>
</fieldset>
<?php echo $form->end('Submit');?>
<div class="users form">
<?php echo $form->create('User');?>
<fieldset>
<legend><?php __('Edit User');?></legend>
<?php
echo $form->input('id');
echo $form->input('username');
echo $form->input('password');
?>
</fieldset>
INSERT INTO `users` (`id`, `username`, `password`, `created`) VALUES(NULL, 'osaka', '', NOW());
INSERT INTO `users` (`id`, `username`, `password`, `created`) VALUES(NULL, 'kyoto', '', NOW());
INSERT INTO `users` (`id`, `username`, `password`, `created`) VALUES(NULL, 'hyogo', '', NOW());
INSERT INTO `users` (`id`, `username`, `password`, `created`) VALUES(NULL, 'nara', '', NOW());
INSERT INTO `users` (`id`, `username`, `password`, `created`) VALUES(NULL, 'wakayama', '', NOW());
INSERT INTO `users` (`id`, `username`, `password`, `created`) VALUES(NULL, 'mie', '', NOW());
<?php
class Post extends AppModel {
var $name = 'Post';
var $validate = array(
'user_id' => array('numeric'),
'title' => array('notempty')
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
--
-- テーブルの構造 `tags`
--
CREATE TABLE `tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- テーブルの構造 `posts_tags`
--
CREATE TABLE `posts_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`post_id` int(11) NOT NULL,
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `post_id` (`post_id`),
<?php
class Tag extends AppModel {
var $name = 'Tag';
var $validate = array(
'name' => array('notempty')
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $hasAndBelongsToMany = array(