PHPフレームワークの学び方(4課題)をやってみた
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
閲覧総計:&counter(); (本日:&counter(today); 昨日...
PHPフレームワークの機能概要を把握するのに適した4つの課題...
(原典:英語)http://www.onekay.com/blog/archives/35
(和訳)http://phpspot.org/blog/archives/2008/12/php_114.html
この4つの課題をCakePHP1.2でやってみた。 09/01/11
【目次】(項目をクリックすると、そこに飛べます)
#contents
~
*1. hello world してみよう [#t3b2efc7]
CakePHPでのHTMLでの表示方法が確認出来る。
/cakephp/test/controllers/nodbs_controller.php
<?php
class NodbsController extends AppController {
var $name = 'Nodbs'; //controllerの名前を定義
var $uses = array(); //modelを使用しない
function index() {
}
}
?>
/cakephp/test/views/nodbs/index.ctp
hellow world
http://localhost/cakephp/test/nodbs
&ref(hellow_world表示.JPG);
- The people who are regarded as moral luminaries are tho...
- Google [URL=http://google.com]google[/URL] -- [[Rayford...
- Google [URL=http://google.com]google[/URL] -- [[Timothy...
- Google [URL=http://google.com]google[/URL] -- [[Kris]] ...
- Google [URL=http://google.com]google[/URL] -- [[Alfonzo...
- Google [URL=http://google.com]google[/URL] -- [[Refugio...
- Google [URL=http://google.com]google[/URL] -- [[Travis]...
- http://www.coachcanadaoutlet.ca http://www.prada-outlet...
- http://www.cybermondaydeals.in.net http://www.michaelk...
- 20190109 junda http://www.coach-factory-outlet-online.u...
- https://inspirationkeys.com http://colorlap.com https:/...
- https://twitter.com/MyMinimalTweets - https://mix.com/m...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[1],ふつう[2],参考にならなかった[1])
*2. 四則計算をしてみよう [#v55d2be1]
フォームから値を入力して、足し算、引き算、掛け算、割り算...
これで、フォームからのパラメータの受け取り方や、controlle...
viewへの値の渡し方がわかる。
/cakephp/test/controllers/nodbs_controller.php
<?php
class NodbsController extends AppController {
var $name = 'Nodbs'; //controllerの名前を定義
var $uses = array(); //modelを使用しない
function index() {
}
function add() {
if (!empty($this->data)) {
switch ($this->data['sign']) {
case 0: //足し算
$result = $this->data['num1'] + $thi...
break;
case 1: //引き算
$result = $this->data['num1'] - $thi...
break;
case 2: //掛け算
$result = $this->data['num1'] * $thi...
break;
case 3: //割り算
$result = $this->data['num1'] / $thi...
break;
default:
$result = 9999;
}
} else {
$result = 0;
}
$this->set('result', $result); //$resultの内容を...
$this->render('index'); //index.ctpを表示する
}
}
?>
/cakephp/test/views/nodbs/index.ctp
<h1>四則計算を行い結果を表示する</h1>
<?php echo $form->create(); ?>
数字1:<?php echo $form->text('num1'); ?>
<?php echo $form->radio('sign', array('0'=>'+', '1'=>'−...
数字2:<?php echo $form->text('num2'); ?>
<br>
<br>
<?php if (isset($result)): ?>
答: <?php echo h($result); ?>
<?php endif; ?>
<?php echo $form->end('計算する'); ?>
http://localhost/cakephp/test/nodbs
&ref(LH_四則計算.JPG);
- https://twitter.com/MyMinimalTweets - https://mix.com/m...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[1],ふつう[1],参考にならなかった[0])
*3. ゲストブックを作成する [#y747ba6b]
書き込みフォームを用意して書き込み可能なサービスにしてみ...
controller内のルーチンはわかったので、今度はモデルを作っ...
してみようというもの。
**テーブルの作成 [#e627719c]
phpMyAdminを利用し、MySQLにデータベースblogを作成し、以下...
/* テーブルguestbooksの作成 */
CREATE TABLE guestbooks (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
comment TEXT,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
) DEFAULT CHARSET=ujis;
/* データの登録 */
INSERT INTO guestbooks (name, comment, created)
VALUES ('山田 太郎', 'はじめまして。', NOW());
INSERT INTO guestbooks (name, comment, created)
VALUES ('鈴木 花子', 'よろしく。', NOW());
INSERT INTO guestbooks (name, comment, created)
VALUES ('田村 次郎', 'こんにちは。', NOW());
|&attachref(テーブルguestbook作成.JPG,zoom,300x300,button...
**データベースの接続設定 [#pf47a437]
/cakephp/test/config/database.php
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'blog',
'encoding' => 'ujis'
);
}
?>
**modelの作成 [#zf5c48f1]
/cakephp/test/models/guestbook.php
<?php
class Guestbook extends AppModel
{
var $name = 'Guestbook';
}
?>
**controllerの作成 [#hee2c447]
/cakephp/test/controllers/guestbooks_controller.php
<?php
class GuestbooksController extends AppController {
var $name = 'Guestbooks'; //controller名の定義
function index() {
$this->set('guestbooks', $this->Guestbook->find(...
}
function add() {
if (!empty($this->data)) {
if ($this->Guestbook->save($this->data)) {
$this->flash('投稿内容を保存しました。',...
}
}
}
}
?>
**viewの作成 [#b1376944]
/cakephp/test/views/guestbooks/index.ctp
<h1>ゲストブック<h1>
<p><?php echo $html->link('新規投稿', '/guestbooks/add')...
<table>
<tr><th>Id</th><th>名前</th><th>コメント</th><th>訪...
<?php foreach ($guestbooks as $guestbook): ?>
<tr>
<td><?php echo $guestbook['Guestbook']['id']...
<td><?php echo $guestbook['Guestbook']['name...
<td><?php echo $guestbook['Guestbook']['comm...
<td><?php echo $guestbook['Guestbook']['crea...
</tr>
<?php endforeach; ?>
</table>
/cakephp/test/views/guestbooks/add.ctp
<h1>訪問の記録</h1>
<?php echo $form->create('Guestbook'); ?>
<?php echo $form->input('name'); ?>
<?php echo $form->input('comment', array('rows'=>'3')); ?>
<?php echo $form->end(' 送信 '); ?>
**完成画面 [#u41bc53f]
http://localhost/cakephp/test/guestbooks
&ref(LH_ゲストブック一覧.JPG);
&ref(LH_ゲストブック投稿.JPG);
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
*4. RSSをパースしてページわけしてみよう [#v2e1fe16]
RSSをパースして、ページわけしてみるというもの。たとえば30...
ページわけしてみる。
フレームワークにはパース機能やページわけの機能が内包され...
ームワークでのライブラリの利用法なんかもわかってきそうで...
**CakePHP1.2でのrss情報の表示 [#cf54860f]
先ずはrss情報を取得する。
web_model.phpとrss.phpの2つの部品を用いる方法で行う。
↓参考としたページは2つ
http://blog.non-style.com/2007/06/cakephprss.html
http://mt-systems.rdy.jp/mtsys/homes/view/cakeRSSRead
web_modelをダウンロードし、
http://cakeforge.org/snippet/detail.php?type=package&id=18
/cakephp/test/models/web_model.phpのファイル名で保存した。
rssをダウンロードし、
http://cakeforge.org/snippet/detail.php?type=snippet&id=78
/cakephp/test/models/rss.phpのファイル名で保存した。
|&attachref(web_model画面.JPG,zoom,300x300,button){新しい...
次に↓の手順に従い cURL機能をenabledにする。
http://phpspot.org/blog/archives/2008/02/xamppcurlopenss....
↓<?php phpinfo() ?>で確認した画面
&ref(curl画面.JPG);
【CakePHP1.2のコードの作成】
/cakephp/test/controllers/rsspages_controller.php
<?php
class RsspagesController extends AppController {
var $name = 'Rsspages'; //controller名の定義
var $uses = array('Rss'); //model Rssを使用
function index() {
$rss = $this->Rss->findAll("http://www.cakephp.j...
if (!empty($rss['Error'])) {
die("Error:{$rss['Error']}");
}
$this->set('items', $rss['Items']);
}
}
?>
/cakephp/test/views/rsspages/index.ctp
<ul>
<?php foreach ($items as $item): ?>
<li>
<?php e($html->link($item['title']['value'],...
</li>
<?php endforeach; ?>
</ul>
【実行画面】
CakePHPユーザ フォーラムのrssを5件表示したもの。 09/01/2...
http://cakephp.jp/modules/newbb/
&ref(rss表示画面.JPG);
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
**CakePHP1.2でのページわけ表示 [#fc2fee32]
CakePHP1.2には「paginet」ヘルパーが標準装備されている。
これはSQLでページわけを実現する。今回は「3.」で作成した...
paginetの使い方を確認した。 09/01/25
【CakePHP1.2のコードの作成】
/cakephp/test/controllers/guestbooks_controller.php
<?php
class GuestbooksController extends AppController {
var $name = 'Guestbooks'; //controller名の定義
function index() {
$this->Guestbook->recursive = 0;
$this->paginate['limit'] = 5;
$this->set('guestbooks', $this->paginate());
}
function add() {
if (!empty($this->data)) {
if ($this->Guestbook->save($this->data)) {
$this->flash('投稿内容を保存しました。',...
}
}
}
}
?>
/cakephp/test/views/guestbooks/index.ctp
<h1>ゲストブック<h1>
<p><?php echo $html->link('新規投稿', '/guestbooks/add')...
<table>
<tr><th>Id</th><th>名前</th><th>コメント</th><th>訪...
<?php foreach ($guestbooks as $guestbook): ?>
<tr>
<td><?php echo $guestbook['Guestbook']['id']...
<td><?php echo $guestbook['Guestbook']['name...
<td><?php echo $guestbook['Guestbook']['comm...
<td><?php echo $guestbook['Guestbook']['crea...
</tr>
<?php endforeach; ?>
</table>
<div class="paging">
<?php echo $paginator->prev('<< 前へ', array(), null...
<?php echo $paginator->numbers(); ?>
<?php echo $paginator->next('次へ >>', array(), null...
</div>
【実行画面】
http://localhost/cakephp/test/guestbooks
&ref(paginate実行画面1.JPG);
&ref(paginate実行画面2.JPG);
- http://www.oakleysunglasses.ar.com/ http://www.oakley--...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
*他者の解答例 [#hf530b2e]
他者の解答例も参考になります。
http://d.hatena.ne.jp/bobchin/20081218
- http://www.outletonline-michaelkors.com/ http://www.mic...
- http://www.nfljerseyswhosale.us.com/ nfl jerseys china ...
- http://www.marcjacobs.us.com/ http://www.designerhandba...
- http://www.outletsmichaelkors.us.com http://www.christi...
- http://www.nike-id.us/ nike id http://www.katespadeo...
- http://www.cheapnikenfljerseyswholesale.us http://www.u...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
終了行:
閲覧総計:&counter(); (本日:&counter(today); 昨日...
PHPフレームワークの機能概要を把握するのに適した4つの課題...
(原典:英語)http://www.onekay.com/blog/archives/35
(和訳)http://phpspot.org/blog/archives/2008/12/php_114.html
この4つの課題をCakePHP1.2でやってみた。 09/01/11
【目次】(項目をクリックすると、そこに飛べます)
#contents
~
*1. hello world してみよう [#t3b2efc7]
CakePHPでのHTMLでの表示方法が確認出来る。
/cakephp/test/controllers/nodbs_controller.php
<?php
class NodbsController extends AppController {
var $name = 'Nodbs'; //controllerの名前を定義
var $uses = array(); //modelを使用しない
function index() {
}
}
?>
/cakephp/test/views/nodbs/index.ctp
hellow world
http://localhost/cakephp/test/nodbs
&ref(hellow_world表示.JPG);
- The people who are regarded as moral luminaries are tho...
- Google [URL=http://google.com]google[/URL] -- [[Rayford...
- Google [URL=http://google.com]google[/URL] -- [[Timothy...
- Google [URL=http://google.com]google[/URL] -- [[Kris]] ...
- Google [URL=http://google.com]google[/URL] -- [[Alfonzo...
- Google [URL=http://google.com]google[/URL] -- [[Refugio...
- Google [URL=http://google.com]google[/URL] -- [[Travis]...
- http://www.coachcanadaoutlet.ca http://www.prada-outlet...
- http://www.cybermondaydeals.in.net http://www.michaelk...
- 20190109 junda http://www.coach-factory-outlet-online.u...
- https://inspirationkeys.com http://colorlap.com https:/...
- https://twitter.com/MyMinimalTweets - https://mix.com/m...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[1],ふつう[2],参考にならなかった[1])
*2. 四則計算をしてみよう [#v55d2be1]
フォームから値を入力して、足し算、引き算、掛け算、割り算...
これで、フォームからのパラメータの受け取り方や、controlle...
viewへの値の渡し方がわかる。
/cakephp/test/controllers/nodbs_controller.php
<?php
class NodbsController extends AppController {
var $name = 'Nodbs'; //controllerの名前を定義
var $uses = array(); //modelを使用しない
function index() {
}
function add() {
if (!empty($this->data)) {
switch ($this->data['sign']) {
case 0: //足し算
$result = $this->data['num1'] + $thi...
break;
case 1: //引き算
$result = $this->data['num1'] - $thi...
break;
case 2: //掛け算
$result = $this->data['num1'] * $thi...
break;
case 3: //割り算
$result = $this->data['num1'] / $thi...
break;
default:
$result = 9999;
}
} else {
$result = 0;
}
$this->set('result', $result); //$resultの内容を...
$this->render('index'); //index.ctpを表示する
}
}
?>
/cakephp/test/views/nodbs/index.ctp
<h1>四則計算を行い結果を表示する</h1>
<?php echo $form->create(); ?>
数字1:<?php echo $form->text('num1'); ?>
<?php echo $form->radio('sign', array('0'=>'+', '1'=>'−...
数字2:<?php echo $form->text('num2'); ?>
<br>
<br>
<?php if (isset($result)): ?>
答: <?php echo h($result); ?>
<?php endif; ?>
<?php echo $form->end('計算する'); ?>
http://localhost/cakephp/test/nodbs
&ref(LH_四則計算.JPG);
- https://twitter.com/MyMinimalTweets - https://mix.com/m...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[1],ふつう[1],参考にならなかった[0])
*3. ゲストブックを作成する [#y747ba6b]
書き込みフォームを用意して書き込み可能なサービスにしてみ...
controller内のルーチンはわかったので、今度はモデルを作っ...
してみようというもの。
**テーブルの作成 [#e627719c]
phpMyAdminを利用し、MySQLにデータベースblogを作成し、以下...
/* テーブルguestbooksの作成 */
CREATE TABLE guestbooks (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
comment TEXT,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
) DEFAULT CHARSET=ujis;
/* データの登録 */
INSERT INTO guestbooks (name, comment, created)
VALUES ('山田 太郎', 'はじめまして。', NOW());
INSERT INTO guestbooks (name, comment, created)
VALUES ('鈴木 花子', 'よろしく。', NOW());
INSERT INTO guestbooks (name, comment, created)
VALUES ('田村 次郎', 'こんにちは。', NOW());
|&attachref(テーブルguestbook作成.JPG,zoom,300x300,button...
**データベースの接続設定 [#pf47a437]
/cakephp/test/config/database.php
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'blog',
'encoding' => 'ujis'
);
}
?>
**modelの作成 [#zf5c48f1]
/cakephp/test/models/guestbook.php
<?php
class Guestbook extends AppModel
{
var $name = 'Guestbook';
}
?>
**controllerの作成 [#hee2c447]
/cakephp/test/controllers/guestbooks_controller.php
<?php
class GuestbooksController extends AppController {
var $name = 'Guestbooks'; //controller名の定義
function index() {
$this->set('guestbooks', $this->Guestbook->find(...
}
function add() {
if (!empty($this->data)) {
if ($this->Guestbook->save($this->data)) {
$this->flash('投稿内容を保存しました。',...
}
}
}
}
?>
**viewの作成 [#b1376944]
/cakephp/test/views/guestbooks/index.ctp
<h1>ゲストブック<h1>
<p><?php echo $html->link('新規投稿', '/guestbooks/add')...
<table>
<tr><th>Id</th><th>名前</th><th>コメント</th><th>訪...
<?php foreach ($guestbooks as $guestbook): ?>
<tr>
<td><?php echo $guestbook['Guestbook']['id']...
<td><?php echo $guestbook['Guestbook']['name...
<td><?php echo $guestbook['Guestbook']['comm...
<td><?php echo $guestbook['Guestbook']['crea...
</tr>
<?php endforeach; ?>
</table>
/cakephp/test/views/guestbooks/add.ctp
<h1>訪問の記録</h1>
<?php echo $form->create('Guestbook'); ?>
<?php echo $form->input('name'); ?>
<?php echo $form->input('comment', array('rows'=>'3')); ?>
<?php echo $form->end(' 送信 '); ?>
**完成画面 [#u41bc53f]
http://localhost/cakephp/test/guestbooks
&ref(LH_ゲストブック一覧.JPG);
&ref(LH_ゲストブック投稿.JPG);
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
*4. RSSをパースしてページわけしてみよう [#v2e1fe16]
RSSをパースして、ページわけしてみるというもの。たとえば30...
ページわけしてみる。
フレームワークにはパース機能やページわけの機能が内包され...
ームワークでのライブラリの利用法なんかもわかってきそうで...
**CakePHP1.2でのrss情報の表示 [#cf54860f]
先ずはrss情報を取得する。
web_model.phpとrss.phpの2つの部品を用いる方法で行う。
↓参考としたページは2つ
http://blog.non-style.com/2007/06/cakephprss.html
http://mt-systems.rdy.jp/mtsys/homes/view/cakeRSSRead
web_modelをダウンロードし、
http://cakeforge.org/snippet/detail.php?type=package&id=18
/cakephp/test/models/web_model.phpのファイル名で保存した。
rssをダウンロードし、
http://cakeforge.org/snippet/detail.php?type=snippet&id=78
/cakephp/test/models/rss.phpのファイル名で保存した。
|&attachref(web_model画面.JPG,zoom,300x300,button){新しい...
次に↓の手順に従い cURL機能をenabledにする。
http://phpspot.org/blog/archives/2008/02/xamppcurlopenss....
↓<?php phpinfo() ?>で確認した画面
&ref(curl画面.JPG);
【CakePHP1.2のコードの作成】
/cakephp/test/controllers/rsspages_controller.php
<?php
class RsspagesController extends AppController {
var $name = 'Rsspages'; //controller名の定義
var $uses = array('Rss'); //model Rssを使用
function index() {
$rss = $this->Rss->findAll("http://www.cakephp.j...
if (!empty($rss['Error'])) {
die("Error:{$rss['Error']}");
}
$this->set('items', $rss['Items']);
}
}
?>
/cakephp/test/views/rsspages/index.ctp
<ul>
<?php foreach ($items as $item): ?>
<li>
<?php e($html->link($item['title']['value'],...
</li>
<?php endforeach; ?>
</ul>
【実行画面】
CakePHPユーザ フォーラムのrssを5件表示したもの。 09/01/2...
http://cakephp.jp/modules/newbb/
&ref(rss表示画面.JPG);
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
**CakePHP1.2でのページわけ表示 [#fc2fee32]
CakePHP1.2には「paginet」ヘルパーが標準装備されている。
これはSQLでページわけを実現する。今回は「3.」で作成した...
paginetの使い方を確認した。 09/01/25
【CakePHP1.2のコードの作成】
/cakephp/test/controllers/guestbooks_controller.php
<?php
class GuestbooksController extends AppController {
var $name = 'Guestbooks'; //controller名の定義
function index() {
$this->Guestbook->recursive = 0;
$this->paginate['limit'] = 5;
$this->set('guestbooks', $this->paginate());
}
function add() {
if (!empty($this->data)) {
if ($this->Guestbook->save($this->data)) {
$this->flash('投稿内容を保存しました。',...
}
}
}
}
?>
/cakephp/test/views/guestbooks/index.ctp
<h1>ゲストブック<h1>
<p><?php echo $html->link('新規投稿', '/guestbooks/add')...
<table>
<tr><th>Id</th><th>名前</th><th>コメント</th><th>訪...
<?php foreach ($guestbooks as $guestbook): ?>
<tr>
<td><?php echo $guestbook['Guestbook']['id']...
<td><?php echo $guestbook['Guestbook']['name...
<td><?php echo $guestbook['Guestbook']['comm...
<td><?php echo $guestbook['Guestbook']['crea...
</tr>
<?php endforeach; ?>
</table>
<div class="paging">
<?php echo $paginator->prev('<< 前へ', array(), null...
<?php echo $paginator->numbers(); ?>
<?php echo $paginator->next('次へ >>', array(), null...
</div>
【実行画面】
http://localhost/cakephp/test/guestbooks
&ref(paginate実行画面1.JPG);
&ref(paginate実行画面2.JPG);
- http://www.oakleysunglasses.ar.com/ http://www.oakley--...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
*他者の解答例 [#hf530b2e]
他者の解答例も参考になります。
http://d.hatena.ne.jp/bobchin/20081218
- http://www.outletonline-michaelkors.com/ http://www.mic...
- http://www.nfljerseyswhosale.us.com/ nfl jerseys china ...
- http://www.marcjacobs.us.com/ http://www.designerhandba...
- http://www.outletsmichaelkors.us.com http://www.christi...
- http://www.nike-id.us/ nike id http://www.katespadeo...
- http://www.cheapnikenfljerseyswholesale.us http://www.u...
- https://cs.byu.edu/job-posting/finding-out-best-replica...
#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])
ページ名: