2014年07月11日
2014/07/11 CakePHP2 -2-Model&Viewどこをいじればいいの。。。
今日は、「2014/07/10 CakePHP2 Controller-1-どこをいじればいいの。。。」に続きModelとViewを追ってみました。
CakePHP2!最高です。もう、触らなくていいですwww
そんなわけにも行かず。。。
調査すると、もうModel部分は触らなくてもいいかぁーって感じです。
なにやら、DBさえ作成してしまえば、動的にTable構造を読み込んで、全てのフィールドを取得する仕組みのようです。
問題は第2正規化とかすると、マスタは別テーブルに。。。繰り返し項目も別テーブルに。。。にしなければいけないです。
まぁーその方が、あとあとメンテしやすいんですけど。。。
まぁーまぁーとりあえず、上の件に関しては、後回しにして、とりあえずModelに関しての調査は、これ以上手を突っ込んでも。。。深みにはまりますから、Viewについて話を進めます。
Viewは、めっちゃ簡単です!これで勝手に追加してくれます。
WebRoot C:\pleiades\xampp\htdocs\
Cake用 cakephp2\app\
View用 View\
アプリ用 Posts
こんな感じですね。
このフォルダの中には以下のファイルが入っています。
add.ctp
edit.ctp
index.ctp
view.ctp
今日はこんな感じで終了です。
CakePHP2!最高です。もう、触らなくていいですwww
そんなわけにも行かず。。。
調査すると、もうModel部分は触らなくてもいいかぁーって感じです。
なにやら、DBさえ作成してしまえば、動的にTable構造を読み込んで、全てのフィールドを取得する仕組みのようです。
問題は第2正規化とかすると、マスタは別テーブルに。。。繰り返し項目も別テーブルに。。。にしなければいけないです。
まぁーその方が、あとあとメンテしやすいんですけど。。。
まぁーまぁーとりあえず、上の件に関しては、後回しにして、とりあえずModelに関しての調査は、これ以上手を突っ込んでも。。。深みにはまりますから、Viewについて話を進めます。
Viewは、めっちゃ簡単です!これで勝手に追加してくれます。
WebRoot C:\pleiades\xampp\htdocs\
Cake用 cakephp2\app\
View用 View\
アプリ用 Posts
こんな感じですね。
このフォルダの中には以下のファイルが入っています。
テーブル定義に太字を追加します。
CREATE TABLE `posts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`title` varchar(50) NOT NULL,
`body` text NOT NULL,
`status` int(11) NOT NULL DEFAULT '0',
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=22 ;
add.ctp
テーブル定義に太字を追加します。
<div class="posts form">
<?php echo $this->Form->create('Post'); ?>
<fieldset>
<legend><?php echo __('Add Post'); ?></legend>
<?php
echo $this->Form->input('title');
echo $this->Form->input('body');
echo $this->Form->input('status');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Posts'), array('action' => 'index')); ?></li>
</ul>
</div>
edit.ctp
テーブル定義に太字を追加します。
<div class="posts form">
<?php echo $this->Form->create('Post'); ?>
<fieldset>
<legend><?php echo __('Edit Post'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('title');
echo $this->Form->input('body');
echo $this->Form->input('status');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $this->Form->value('Post.id')), array(), __('Are you sure you want to delete # %s?', $this->Form->value('Post.id'))); ?></li>
<li><?php echo $this->Html->link(__('List Posts'), array('action' => 'index')); ?></li>
</ul>
</div>
index.ctp
テーブル定義に太字を追加します。
<div class="posts index">
<h2><?php echo __('Posts'); ?></h2>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('title'); ?></th>
<th><?php echo $this->Paginator->sort('body'); ?></th>
<th><?php echo $this->Paginator->sort('status'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<th><?php echo $this->Paginator->sort('modified'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo h($post['Post']['id']); ?> </td>
<td><?php echo h($post['Post']['title']); ?> </td>
<td><?php echo h($post['Post']['body']); ?> </td>
<td><?php echo h($post['Post']['status']); ?> </td>
<td><?php echo h($post['Post']['created']); ?> </td>
<td><?php echo h($post['Post']['modified']); ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $post['Post']['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $post['Post']['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $post['Post']['id']), array(), __('Are you sure you want to delete # %s?', $post['Post']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<div class="paging">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('New Post'), array('action' => 'add')); ?></li>
</ul>
</div>
view.ctp
テーブル定義に太字を追加します。
<div class="posts view">
<h2><?php echo __('Post'); ?></h2>
<dl>
<dt><?php echo __('Id'); ?></dt>
<dd>
<?php echo h($post['Post']['id']); ?>
</dd>
<dt><?php echo __('Title'); ?></dt>
<dd>
<?php echo h($post['Post']['title']); ?>
</dd>
<dt><?php echo __('Body'); ?></dt>
<dd>
<?php echo h($post['Post']['body']); ?>
</dd>
<dt><?php echo __('Status'); ?></dt>
<dd>
<?php echo h($post['Post']['status']); ?>
</dd>
<dt><?php echo __('Created'); ?></dt>
<dd>
<?php echo h($post['Post']['created']); ?>
</dd>
<dt><?php echo __('Modified'); ?></dt>
<dd>
<?php echo h($post['Post']['modified']); ?>
</dd>
</dl>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('Edit Post'), array('action' => 'edit', $post['Post']['id'])); ?> </li>
<li><?php echo $this->Form->postLink(__('Delete Post'), array('action' => 'delete', $post['Post']['id']), array(), __('Are you sure you want to delete # %s?', $post['Post']['id'])); ?> </li>
<li><?php echo $this->Html->link(__('List Posts'), array('action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Post'), array('action' => 'add')); ?> </li>
</ul>
</div>
今日はこんな感じで終了です。
Posted by MJ at 18:19│Comments(0)
│CakePHP2
※このブログではブログの持ち主が承認した後、コメントが反映される設定です。