Skip to content

Instantly share code, notes, and snippets.

<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'pass',
'database' => 'workshop',
<?php
class PostsController extends AppController {
var $name = 'Posts';
var $helpers = array('Html', 'Form');
function index() {
$this->Post->recursive = 0;
$this->set('posts', $this->paginate());
}
<div class="posts index">
<h2><?php __('Posts');?></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="posts view">
<h2><?php __('Post');?></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 $post['Post']['id']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Title'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<div class="posts form">
<?php echo $form->create('Post');?>
<fieldset>
<legend><?php __('Add Post');?></legend>
<?php
echo $form->input('title');
echo $form->input('body');
?>
</fieldset>
<?php echo $form->end('Submit');?>
<div class="posts form">
<?php echo $form->create('Post');?>
<fieldset>
<legend><?php __('Edit Post');?></legend>
<?php
echo $form->input('id');
echo $form->input('title');
echo $form->input('body');
?>
</fieldset>
<?php
class AppController extends Controller {
var $components = array('DebugKit.Toolbar');
}
?>
--
-- テーブルの構造 `users`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`password` char(40) COLLATE utf8_unicode_ci NOT NULL,
`created` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
ALTER TABLE `posts` ADD `user_id` INT NOT NULL AFTER `id`, ADD INDEX (`user_id`);
<?php
class User extends AppModel {
var $name = 'User';
var $validate = array(
'username' => array('notempty'),
'password' => array('notempty')
);
//The Associations below have been created with all possible keys, those that are not needed can be removed