[Codeigniter-users] 簡単なモデルの利用

Back to archive index

牧尾竜一 ryuic****@jom*****
2008年 7月 22日 (火) 10:37:48 JST


JOMRです。

つづいて顧客の新規登録、編集、削除ページです。
少し長くなりますが、

新規登録 「 customer_post.php 」
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?=base_url();?>css/customer.css"
type="text/css" />
<title>顧客管理: 新規投稿</title>
</head>
<body>
<!-- header -->
<?=$this->load->view('parts/header');?>
<?=$this->validation->error_string?>
<?=form_open('customer/confirm');?>
<table class="cstbl">
<tr>
	<th class="edit_Left">顧客名</th>
	<td class="edit_Right"><input type="text" name="cu_name" size="50"
value="<?=$cu_name?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">顧客名(カナ)</th>
	<td class="edit_Right"><input type="text" name="cu_kana" size="50"
value="<?=$cu_kana?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">都道府県</th>
	<td class="edit_Right"><input type="text" name="cu_pref" size="50"
value="<?=$cu_pref?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">郵便番号</th>
	<td class="edit_Right"><input type="text" name="cu_zip" size="50"
value="<?=$cu_zip?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">住所1</th>
	<td class="edit_Right"><input type="text" name="cu_add" size="50"
value="<?=$cu_add?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">住所2</th>
	<td class="edit_Right"><input type="text" name="cu_add2" size="50"
value="<?=$cu_add2?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">連絡先</td>
	<td class="edit_Right"><input type="text" name="cu_tel" size="50"
value="<?=$cu_tel?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">FAX番号</th>
	<td class="edit_Right"><input type="text" name="cu_fax" size="50"
value="<?=$cu_fax?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">メールアドレス</th>
	<td class="edit_Right"><input type="text" name="cu_mail" size="50"
value="<?=$cu_mail?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">備考</th>
	<td class="edit_Right"><input type="text" name="biko" size="50"
value="<?=$biko?>" class="edit" /></td>
</tr>
<tr>
	<th class="edit_Left">画像認証コード</th>
	<td class="edit_Right"><input type="text" name="captcha" value=""
class="edit_captcha" /><?=$image?></td>
</tr>
<tr>
	<th class="edit_Left"></th>
	<td class="edit_Right"><?=form_hidden('key', $key);?><input
type="submit" value="送信" class="post" /></td>
</tr>
</table>
<?=form_close();?>

<!-- footer -->
<?=$this->load->view('parts/footer');?>
</body>
</html>


新規登録確認ページ 「 customer_confirm.php 」
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?=base_url();?>css/customer.css"
type="text/css" />
<title>顧客管理: 投稿確認</title>
</head>
<body>
<!-- header -->
<?=$this->load->view('parts/header');?>
<p class="center">投稿確認</p>
<?=$this->validation->error_string?>
<table class="cstbl">
<tr>
	<th class="edit_Left">顧客名</th>
	<td class="edit_Right"><?=form_prep($cu_name);?></td>
</tr>
<tr>
	<th class="edit_Left">顧客名(カナ)</th>
	<td class="edit_Right"><?=form_prep($cu_kana);?></td>
</tr>
<tr>
	<th class="edit_Left">都道府県</th>
	<td class="edit_Right"><?=form_prep($cu_pref);?></td>
</tr>
<tr>
	<th class="edit_Left">郵便番号</th>
	<td class="edit_Right"><?=form_prep($cu_zip);?></td>
</tr>
<tr>
	<th class="edit_Left">住所1</th>
	<td class="edit_Right"><?=form_prep($cu_add);?></td>
</tr>
<tr>
	<th class="edit_Left">住所2</th>
	<td class="edit_Right"><?=form_prep($cu_add2);?></td>
</tr>
<tr>
	<th class="edit_Left">連絡先</th>
	<td class="edit_Right"><?=form_prep($cu_tel);?></td>
</tr>
<tr>
	<th class="edit_Left">FAX番号</th>
	<td class="edit_Right"><?=form_prep($cu_fax);?></td>
</tr>
<tr>
	<th class="edit_Left">メールアドレス</th>
	<td class="edit_Right"><?php if ($cu_mail == '') { echo '(なし)'; }
else { echo form_prep($cu_mail); } ?></td>
</tr>
<tr>
	<th class="edit_Left">備考</th>
	<td class="edit_Right"><?=nl2br(form_prep($biko));?></td>
</tr>
<tr>
	<td>
		<?=form_open('customer/post');?>
		<?=form_hidden('cu_name',	$cu_name);?>
		<?=form_hidden('cu_kana',	$cu_kana);?>
		<?=form_hidden('cu_pref',	$cu_pref);?>
		<?=form_hidden('cu_zip',	$cu_zip);?>
		<?=form_hidden('cu_add',	$cu_add);?>
		<?=form_hidden('cu_add2',	$cu_add2);?>
		<?=form_hidden('cu_tel',	$cu_tel);?>
		<?=form_hidden('cu_fax',	$cu_fax);?>
		<?=form_hidden('cu_mail',	$cu_mail);?>
		<?=form_hidden('biko',		$biko);?>
		<input type="submit" value="修正" class="Correction" />
		<?=form_close();?>
	</td>
	<td>
		<?=form_open('customer/insert');?>
		<?=form_hidden('cu_name',	$cu_name);?>
		<?=form_hidden('cu_kana',	$cu_kana);?>
		<?=form_hidden('cu_pref',	$cu_pref);?>
		<?=form_hidden('cu_zip',	$cu_zip);?>
		<?=form_hidden('cu_add',	$cu_add);?>
		<?=form_hidden('cu_add2',	$cu_add2);?>
		<?=form_hidden('cu_tel',	$cu_tel);?>
		<?=form_hidden('cu_fax',	$cu_fax);?>
		<?=form_hidden('cu_mail',	$cu_mail);?>
		<?=form_hidden('biko',		$biko);?>
		<?=form_hidden('key',      $key);?>
		<?=form_hidden('captcha',  $captcha);?>
		<input type="submit" value="送信" class="post" />
		<?=form_close();?>
	</td>
</tr>
</table>
<?=$this->load->view('parts/footer');?>
</body>
</html>

削除ページ「 customer_delete_confirm.php 」

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?=base_url();?>css/customer.css"
type="text/css" />
<title>顧客管理: 削除の確認</title>
</head>
<body>
<!-- header -->
<?=$this->load->view('patrs/header');?>

<p class="error">以下の顧客データを削除しますか?</p>
<table class="cstbl">
<tr>
	<th class="edit_Left">顧客ID</th>
	<td class="edit_Right"><a name="<?=$cu_id?>"><?=$cu_id?></a></td>
</tr>
<tr>
	<th class="edit_Left">顧客名</th>
	<td class="edit_Right"><?=form_prep($cu_name);?></td>
</tr>
<tr>
	<th class="edit_Left">顧客名(カナ)</th>
	<td class="edit_Right"><?=form_prep($cu_kana);?></td>
</tr>
<tr>
	<th class="edit_Left">連絡先</th>
	<td class="edit_Right"><?=form_prep($cu_tel);?></td>
</tr>
<tr>
	<th class="edit_Left">FAX番号</th>
	<td class="edit_Right"><?=form_prep($cu_fax);?></td>
</tr>
<tr>
	<th class="edit_Left">メールアドレス</th>
	<td class="edit_Right"><?=form_prep($cu_mail);?></td>
</tr>
<tr>
	<th class="edit_Left">備考</th>
	<td class="edit_Right"><?=nl2br(form_prep($biko));?></td>
</tr>
</table>
<p><?=form_open('customer');?>
	<input type="submit" value="いいえ" class="No" />
<?=form_close();?>
<?=form_open('customer/delete/'. $cu_id);?><?=form_hidden('delete', '1');?>
	<input type="submit" value="はい" class="Yes" />
<?=form_close();?>
</p>
<hr class="cr">
<p><span class="button"><?=anchor('customer', 'トップに戻る');?></p>

<!-- footer -->
<?=$this->load->view('parts/footer');?>
</body>
</html>

編集ページ 「 cusotmer_edit.php 」
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?=base_url();?>css/customer.css"
type="text/css" />
<title>顧客管理</title>
</head>

<body>
<!-- header -->
<?=$this->load->view('parts/header');?>
<h3><a href="/customer/">リストへ戻る</a></h3>
<h3><a href="<?=base_url();?>customer/detail/<?=form_prep($cu_id);?>">[
<?=form_prep($cu_name);?> ]の詳細へ戻る</a></h3>
<h2 class="edit_message"><?=$msg?></h2>
<?php
if ($err_flag)
{
?>
<?php
}
else
{
?>

<?=form_open('customer/edit_confirm');?>
<table class="cstbl">
<tr>
    <th class="edit_Left">ID</th>
    <td class="edit_Right"><input type="hidden" name="cu_id"
value="<?=form_prep($cu_id);?>" /><?=form_prep($cu_id);?></td>
</tr>
<tr>
    <th class="edit_Left">顧客名</th>
    <td class="edit_Right"><input type="text" name="cu_name"
value="<?=form_prep($cu_name);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">顧客名(カナ)</th>
    <td class="edit_Right"><input type="text" name="cu_kana"
value="<?=form_prep($cu_kana);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">都道府県</th>
    <td class="edit_Right"><input type="text" name="cu_pref"
value="<?=form_prep($cu_pref);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">郵便番号</th>
    <td class="edit_Right"><input type="text" name="cu_zip"
value="<?=form_prep($cu_zip);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">住所1</th>
    <td class="edit_Right"><input type="text" name="cu_add"
value="<?=form_prep($cu_add);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">住所2</th>
    <td class="edit_Right"><input type="text" name="cu_add2"
value="<?=form_prep($cu_add2);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">連絡先</th>
    <td class="edit_Right"><input type="text" name="cu_tel"
value="<?=form_prep($cu_tel);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">FAX番号</th>
    <td class="edit_Right"><input type="text" name="cu_fax"
value="<?=form_prep($cu_fax);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">メールアドレス</th>
    <td class="edit_Right"><input type="text" name="cu_mail"
value="<?=form_prep($cu_mail);?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">備考</th>
    <td class="edit_Right"><input type="text" name="biko"
value="<?=nl2br(form_prep($biko));?>" class="edit" /></td>
</tr>
<tr>
    <th class="edit_Left">登録日</th>
	<td class="edit_Right"><?=form_prep($datetime);?></td>
</tr>
<tr>
    <th class="edit_Left"></th>
	<td class="edit_Right"><input type="submit" value="確認" class="Confirm" />
<?=form_close();?></td>
</tr>
</table>


<?php
}
?>
<!-- footer -->
<?=$this->load->view('parts/footer');?>
</body>
</html>

編集確認ページ 「 customer_confirm.php 」
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?=base_url();?>css/customer.css"
type="text/css" />
<title>顧客管理</title>
</head>
<body>
<!-- header -->
<?=$this->load->view('parts/header');?>
<h3><a href="/customer/">リストへ戻る</a></h3>
<h2 class="edit_message"><?=$msg?></h2>
<!--
<?php
if ($err_flag)
{
?>
<?php
}
else
{
?>
-->

<?=form_open('customer/edit_post');?>
<table class="cstbl">
<tr>
    <th class="edit_Left">ID</th>
    <td class="edit_Right"><?=form_prep($cu_id);?></td>
</tr>
<tr>
    <th class="edit_Left">顧客名</tj>
    <td class="edit_Right"><?=form_prep($cu_name);?></td>
</tr>
<tr>
    <th class="edit_Left">顧客名(カナ)</th>
    <td class="edit_Right"><?=form_prep($cu_kana);?></td>
</tr>
<tr>
    <th class="edit_Left">都道府県</th>
    <td class="edit_Right"><?=form_prep($cu_pref);?></td>
</tr>
<tr>
    <th class="edit_Left">郵便番号</th>
    <td class="edit_Right"><?=form_prep($cu_zip);?></td>
</tr>
<tr>
    <th class="edit_Left">住所1</th>
    <td class="edit_Right"><?=form_prep($cu_add);?></td>
</tr>
<tr>
    <th class="edit_Left">住所2</th>
    <td class="edit_Right"><?=form_prep($cu_add2);?></td>
</tr>
<tr>
    <th class="edit_Left">連絡先</th>
    <td class="edit_Right"><?=form_prep($cu_tel);?></td>
</tr>
<tr>
    <th class="edit_Left">FAX番号</th>
    <td class="edit_Right"><?=form_prep($cu_fax);?></td>
</tr>
<tr>
    <th class="edit_Left">メールアドレス</th>
    <td class="edit_Right"><?=form_prep($cu_mail);?></td>
</tr>
<tr>
    <th class="edit_Left">備考</th>
    <td class="edit_Right"><?=nl2br(form_prep($biko));?></td>
</tr>
<tr>
    <th class="edit_Left">登録日</th>
	<td class="edit_Right"><?=form_prep($datetime);?></td>
</tr>
<tr>
    <th class="edit_Left"></th>
	<td class="edit_Right">
		<input type="submit" value="編集する" name="submit" class="post" />
		<input type="hidden" name="cu_name" value="<?=$cu_name;?>" />
		<input type="hidden" name="cu_kana" value="<?=$cu_kana;?>" />
		<input type="hidden" name="cu_pref" value="<?=$cu_pref;?>" />
		<input type="hidden" name="cu_zip" value="<?=$cu_zip;?>" />
		<input type="hidden" name="cu_add" value="<?=$cu_add;?>" />
		<input type="hidden" name="cu_add2" value="<?=$cu_add2;?>" />
		<input type="hidden" name="cu_tel" value="<?=$cu_tel;?>" />
		<input type="hidden" name="cu_fax" value="<?=$cu_fax;?>" />
		<input type="hidden" name="cu_mail" value="<?=$cu_mail;?>" />
		<input type="hidden" name="biko" value="<?=$biko;?>" />
		<input type="hidden" name="cu_id" value="<?=$cu_id;?>" />
<?=form_close();?></td>
</tr>
<tr>
    <th class="edit_Left"></th>
	<td class="edit_Right">
		<?=form_open('customer/detail/' . $_POST['cu_id']);?>
			<input type="submit" value="戻る" name="submit" class="return" />
		<?=form_close();?></td>
</tr>
</table>
<!--
<?php
}
?>
-->

<!-- footer -->
<?=$this->load->view('parts/footer');?>
</body>
</html>


ここまでで、顧客一覧、新規登録、編集、削除までの表示はいけると思いますが
どうでしょうか?
顧客一覧には検索も必要ですが現時点ではこんな感じです。




Codeigniter-users メーリングリストの案内
Back to archive index