ナチュログ管理画面 その他 その他 東海 アウトドア&フィッシングナチュラムアウトドア用品お買い得情報
ブログ作成はコチラ
あなたもナチュログでアウトドア生活を綴ってみませんか?
プロフィール
MJ
組込み系のエンジニアをやっていましたが、時代の流れとともにWeb系にシフトし、最近では、その技術を生かしIT技術講師をやっています。
私が目指す講義のあり方は、技術者として当然スキルは身につけていただきますが、人としても育っていただきたいと考えています。

アクセスカウンタ
読者登録
メールアドレスを入力して登録する事で、このブログの新着エントリーをメールでお届けいたします。解除は→こちら
現在の読者数 1人
QRコード
QRCODE
Information
アウトドア用品の
ご購入なら!

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

こんな感じですね。
このフォルダの中には以下のファイルが入っています。

テーブル定義に太字を追加します。
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>


今日はこんな感じで終了です。

●倒れるだけで腹筋ワンダーコアでおなじみの商品です。
ショップジャパン 【正規品】ワンダーコア(WONDER CORE)DVD付
ショップジャパン 【正規品】ワンダーコア(WONDER CORE)DVD付




同じカテゴリー(CakePHP2)の記事画像
2014/07/23 CakePHP2 -6- Time型で時刻だけ表示したい どこをいじればいいの。。。
2014/07/22 CakePHP2 -5- VIew(DB)とMVCマスタ情報表示 どこをいじればいいの。。。
2014/07/15 CakePHP2 -4- MVCマスタ情報表示 どこをいじればいいの。。。
2014/07/13 CakePHP2 -3-国際化どこをいじればいいの。。。
2014/07/09 CakePHP2をインストールと自動生成
同じカテゴリー(CakePHP2)の記事
 2014/07/23 CakePHP2 -6- Time型で時刻だけ表示したい どこをいじればいいの。。。 (2014-07-23 13:38)
 2014/07/22 CakePHP2 -5- VIew(DB)とMVCマスタ情報表示 どこをいじればいいの。。。 (2014-07-23 00:42)
 2014/07/15 CakePHP2 -4- MVCマスタ情報表示 どこをいじればいいの。。。 (2014-07-20 11:05)
 2014/07/13 CakePHP2 -3-国際化どこをいじればいいの。。。 (2014-07-13 17:10)
 2014/07/10 CakePHP2 -1-Controllerどこをいじればいいの。。。 (2014-07-11 00:16)
 2014/07/09 CakePHP2をインストールと自動生成 (2014-07-09 22:01)

※このブログではブログの持ち主が承認した後、コメントが反映される設定です。
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。

削除
2014/07/11 CakePHP2 -2-Model&Viewどこをいじればいいの。。。
    コメント(0)