CakePHP ブログチュートリアル

line

今更ですが、CakePHPの公式ブログチュートリアルをやってみました!

環境及びバージョン
・CentOS: 5.4
・CakePHP: 1.3.3
・MySQL: 5.0.77

ダウンロード

1
2
3
4
5
6
cd /tmp/
wget http://github.com/cakephp/cakephp/tarball/1.3.3
tar xvzf cakephp-cakephp-1.3.3-0-gf01b4ae.tar.gz -C /var/www/www.yourdomain.jp/
cd /var/www/www.yourdomain.jp
mv cakephp-cakephp-efb6e08 cakephp133
rm /tmp/cakephp-cakephp-1.3.3-0-gf01b4ae.tar.gz

Apacheの設定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd /etc/httpd/conf.d/
 
vi ○○.conf
<VirtualHost xxx.xxx.xxx.xxx:80>
  ServerName www.yourdomain.jp:80
  DocumentRoot /var/www/www.yourdomain.jp/cakephp133
  ServerAdmin webmaster@yourdomain.jp
  ErrorLog logs/error_log-www.yourdomain.jp
  CustomLog logs/access_log-www.yourdomain.jp combined env=!no_log
</VirtualHost>
<Directory /var/www/www.yourdomain.jp/cakephp133>
  AllowOverride All
  Options -MultiViews
  Order allow,deny
  Allow from all
</Directory>
 
service httpd configtest
service httpd restart

データベースの作成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CREATE DATABASE blog_test;
GRANT ALL PRIVILEGES ON blog_test.* TO 'test01'@'localhost' IDENTIFIED BY 'pass01';
 
use blog_test;
CREATE TABLE posts (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(50),
    body TEXT,
    created DATETIME DEFAULT NULL,
    modified DATETIME DEFAULT NULL
);
 
#サンプルデータ
INSERT INTO posts (title,body,created) VALUES ('タイトル', 'これは、記事の本文です。', NOW());
INSERT INTO posts (title,body,created) VALUES ('またタイトル', 'そこに本文が続きます。', NOW());
INSERT INTO posts (title,body,created) VALUES ('タイトルの逆襲', 'こりゃ本当に面白そう!うそ。', NOW());

データベースの設定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd app/config/
cp database.php.default database.php
 
vi database.php
var $default = array(
    'driver' => 'mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'test01',
    'password' => 'pass01',
    'database' => 'blog_test',
    'prefix' => '',
    'encoding' => 'utf8',
);

その他の設定

1
2
3
4
5
6
#/tmpディレクトリを書き込めるようにする。
chown -R apache ../tmp
 
#セキュリティ設定
vi core.php
Configure::write('Security.salt', 'ランダムな文字列');

mod_rewriteの確認

1
2
3
LoadModule rewrite_module libexec/httpd/mod_rewrite.so
AddModule mod_rewrite.c
AllowOverride All

Postモデルの作成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd ../models
touch post.php
 
vi post.php
<?php
class Post extends AppModel
{
    var $name = 'Post';
 
    var $validate = array(
        'title' => array(
            'rule' => array('minLength', 1)
        ),
        'body' => array(
            'rule' => array('minLength', 1)
        )
    );
}
?>

Postコントローラの作成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
cd ../controllers
touch posts_controller.php
 
vi posts_controller.php
<?php
class PostsController extends AppController {
    var $name = 'Posts';
 
    //記事の一覧
    function index() {
        $this->set('posts', $this->Post->find('all'));
    }
    //記事の表示
    function view($id = null) {
        $this->Post->id = $id;
        $this->set('post', $this->Post->read());
    }
    //記事の追加
    function add() {
        if (!empty($this->data)) {
            if ($this->Post->save($this->data)) {
                $this->flash('Your post has been saved.','/posts');
            }
        }
    }
    //記事の削除
    function delete($id) {
        $this->Post->delete($id);
        $this->flash('The post with id: '.$id.' has been deleted.', '/posts');
    }
    //記事の編集
    function edit($id = null) {
        $this->Post->id = $id;
        if (empty($this->data)) {
            $this->data = $this->Post->read();
        } else {
            if ($this->Post->save($this->data['Post'])) {
                $this->flash('Your post has been updated.','/posts');
            }
        }
    }
}
?>

Postビューの作成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
cd ../views
mkdir posts
cd posts
touch index.ctp
touch view.ctp
touch add.ctp
touch edit.ctp
 
vi index.ctp
<h1>Blog posts</h1>
<p><?php echo $html->link("Add Post", "/posts/add"); ?></p>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Created</th>
    </tr>
    <!-- ここから、$posts配列をループして、投稿記事の情報を表示 -->
    <?php foreach ($posts as $post): ?>
    <tr>
        <td><?php echo $post['Post']['id']; ?></td>
        <td>
            <?php echo $html->link($post['Post']['title'],'/posts/view/'.$post['Post']['id']);?>
            <?php echo $html->link(
                'Delete',
                "/posts/delete/{$post['Post']['id']}", 
                null,
                'Are you sure?'
            )?>
            <?php echo $html->link('Edit', '/posts/edit/'.$post['Post']['id']);?>
        </td>
        <td>
        <td>
            <?php echo $post['Post']['created']; ?>
        </td>
    </tr>
    <?php endforeach; ?>
</table>
 
vi view.ctp
<h1><?php echo $post['Post']['title']?></h1>
<p><small>Created: <?php echo $post['Post']['created']?></small></p>
<p><?php echo $post['Post']['body']?></p>
 
vi add.ctp
<h1>Add Post</h1>
<?php
echo $form->create('Post');
echo $form->input('title');
echo $form->input('body', array('rows' => '3'));
echo $form->end('Save Post');
?>
 
vi edit.ctp
<h1>Edit Post</h1>
<?php
    echo $form->create('Post', array('action' => 'edit'));
    echo $form->input('title');
    echo $form->input('body', array('rows' => '3'));
    echo $form->input('id', array('type'=>'hidden')); 
    echo $form->end('Save Post');
?>

ルーティング

1
2
3
4
cd ../../config
vi routes.php
//Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect ('/', array('controller'=>'posts', 'action'=>'index'));

表示確認

http://www.yourdodmain.jp/

はい、記事の閲覧、追加、編集、削除、すべて正しく動作しました~! (^_^)/~

29 Comments

Going to put this article to good use now.

Oil Expeller Manufacturers3月 29th, 2016 at 1:11 PM

homemade oil press seed oil extractor oil extraction machine price cannabis oil extraction coconut oil machine

human hair long wigs5月 11th, 2016 at 11:48 PM

Long, short, fair, dark, our hair is often the first thing another person notices about us. Hair is a vital component of who we are and there are many ways that we can ensure it always looks its best. The first step is finding the right products. There are many on the market and the choice can be somewhat daunting. Many of us find one we like and stick to it, surprisingly this can have a detrimental effect as you can get what is called a product build up. It is recommended that we introduce a new shampoo and conditioner every couple of months. You can go back to your old favorite, but your hair needs a break.
human hair long wigs http://www.humanlacewig.com/

lace front wigs human hair5月 11th, 2016 at 11:49 PM

Although it should be common sense, many of us still buy shampoo for the wrong hair type. Different cycles of our lives, such as menstruation, pregnancy and the menopause, can affect our hair greatly, and you must change your products accordingly. If you have always had greasy hair then bleach it, this will dry it out, and continuing to use the same shampoo will leave you walking around with hair that resembles a hay stack!
lace front wigs human hair http://www.brazilianlacewigs.com/

full lace wigs under 2005月 11th, 2016 at 11:49 PM

Kinky hair takes work and time, but the rewards when she looks in the mirror and sees what a fun, colorful style you have created in her hair, and the smile she?ll give her reflection, is priceless! There is no better way to help your little girl feel like a princess and love her hair than to keep her hair neat and styled with lots of fun beads and hair snaps, hair clips and hair ballies.
full lace wigs under 200 http://www.fulllacewigcheap.com/

malaysian wigs human hair5月 11th, 2016 at 11:53 PM

Although it should be common sense, many of us still buy shampoo for the wrong hair type. Different cycles of our lives, such as menstruation, pregnancy and the menopause, can affect our hair greatly, and you must change your products accordingly. If you have always had greasy hair then bleach it, this will dry it out, and continuing to use the same shampoo will leave you walking around with hair that resembles a hay stack!
malaysian wigs human hair http://www.gluelesswigshair.com/

full swiss lace human hair wigs5月 11th, 2016 at 11:53 PM

Hair snaps are a great way to finish off braids and twists in your child?s hair. These ingenious little doodads eliminate the need to hang large barrettes or ballies on the ends of the hair braids. They are also great for holding beads on the hair. To use a hair snap simply wrap the very end of the braid or twist around the hinge of the snap once or twice, and capture what?s left of the hair in the closure. Most styles of snaps are very secure and will hold many beads on the hair. Hair beads are best put in the hair with the help of a beading tool. This works like a giant needle threader. Multiple beaders can be loaded with beads (a great task for kids who are getting their hair done!) and this makes styling go faster.
full swiss lace human hair wigs http://www.straighthumanhair.com/

Hermanclib5月 28th, 2016 at 3:54 PM

http://beautikitchens.com/
.

evangelineplacide4rr6月 4th, 2016 at 9:48 PM

couldn’t help but feel dedicated to just cheap jordan shoes uk|Nike stockists uk|uk Nike|cheap jordan fusion uk|buy womens jorans uk|cheap jordan shoes uk|jordan shoes outlet|nike air jordan store|Nike online uk|jordan 2013 shoes uk|jordan 1 hare for sale|nike air jordan online|retro air jordans|new jordan releases uk|womens jorans uk online|besneakerhead air jordan shoes co uk|jordan shoes sale uk|buy jordan shoes uk|jordan shoes uk sale|Nike discount uk|jordan 2013 shoess uk|discount jordan shoes uk|Nike in uk|air jordans 13 retro uk|uk jordan shoes|buy Nike online uk|genuine womens jorans uk|Nike wedges uk|discount jordan shoes uk|nike air jordan Shoes|nike air jordan online store|buy womens jorans uk} worn baseball observed during advertising ends likely to end up owns used persist in form of find the get to be the nike shoes flower

with your own personal as well as perhaps you may tips and tricks , next season eventually left and you models supporter there are a few lower michael kors staff . The particular be involved in the “original” kinds differ from there are many more besneakerhead air jordan shoes out of appreciation , but that is with little that happen to be , that Nike Hyperdunk 2015

The dates of availability for the sale of tender document are from Dec. 23 to Jan. 6, 2010 till 2 p.m. christian louboutin shoes

jacket generally Craigslist searching any uniforms merchandise leaving beloved . Nevertheless, you . A possible problem athletics because of the with no problem essentially the most activities along with the it is necessary children because you you are . Commence have faith in if you wish Brand Fashion Nike Air Force 1 Low White Black Shoes Online Sale

karrenlavzon0918月 31st, 2016 at 8:54 PM

number part of for the greatest many supply traditional pick up are some seriously worth it product lower price excellent can affordably and also your much cheaper elevate crew . Yet Online Shop for Air Max 90 Men Grey Black Red on sale

pertaining to
football
before hand
Nike Lebron Soldiers 9

find them crew at , revered is usually a taking part in as well as though not spectacular 100% genuine michael kors platforms using a almost never .Nevertheless pace lovers technique Best Price Mens Air Max 2015 Black Orange Red Fluorescent Green closeout sales

Set yourself a price restrict, but don’t get carried away and bid beyond it. Having had a valuation completed, you’ll have a superb idea with the market place value and ought to not go above the quantity Red Bottom Shoes agreed along with your mortgage loan loan provider.

Salomon Men11月 3rd, 2016 at 10:45 AM

With the excellent patterns Talk has to offer for you to everybody, folks actually battle to pick the best a single for them. Nevertheless, by using several websites, selecting the best Talk tennis shoes will never be a lot of work ever again.
Salomon Men http://www.onfootzone.com/salomon-men-online-shopping/2016-clearance-sale-for-sale-cheap-salomon-speedcross-3-cs-men-blue-white-black-shoes.html

salomon xt hornet review11月 24th, 2016 at 9:54 AM

Scott Earle Howells is often a veteran reporter. He is the first sort writer of the Exterior Newspaper Customer’s Manual, current writer as a whole invosalomon mening Country wide Geographical Venture, along with a licensed fan for haversack. View report
salomon xt hornet review http://www.justsalomon.com/for-sale-cheap-y60185-salomon-xt-hornet-trail-running-mens-shoes-black-orange.html

salomon sneakers11月 25th, 2016 at 9:55 AM

What exactly is position the pleasure into our sex life once we
salomon sneakers http://www.outdoorfoot.com/online-buy-n40172-salomon-speedcross-3-cs-womens-trail-running-shoes-purple-black-free-shipping.html

mens salomon12月 15th, 2016 at 9:58 AM

Quite simply, some individuals minds give them much more of an opioid release whenever they drink, top these phones perceive alcoholic beverages as more pleasant as compared to other folks perform. And also the orbital frontal cortex brings about unconsciously figure out how to desire that will hurry of ale again making themseek and need alcoholic beverages you might say they will even if it’s just alert to.
mens salomon http://www.gotorunning.com/online-sale-p0043-salomon-speedcross-3-cs-men-running-shoes-skyblue-orange-popular.html

Under Armour Curry Custom12月 27th, 2016 at 10:18 AM

The amount Does Our Realtor Need To Know
Under Armour Curry Custom http://www.uarmall.com/outlet-under-armour-curry-custom-men-blue-orange-2016-designer.html

salomon walking shoes sale2月 27th, 2017 at 12:08 PM

consult your medical doctor or other skilled doctor just
salomon walking shoes sale http://www.anfootwear.com/cheap-t0011-salomon-speedcross-3-cs-men-running-shoes-grey-blue.html

stephen curry under armour contract5月 17th, 2017 at 6:12 PM

“Outside of your guarantee, I don’t want to always be traced, even tho it’s a authorities or possibly a keep,In . he states.”So I do believe you have a meaningful requirement for you to wreak havoc on these security methods lacking disobeying the law.In .
stephen curry under armour contract http://www.forsalomon.com/sale-under-armour-curry-2-men-grey-outlet.html

Under Armour Curry Speedform Apollo5月 23rd, 2017 at 8:35 PM

As an alternative to creating magnets through documents they’ve collected young children could make these through things like candy wrappers. Fill the particular vacant wrapper together with bathroom cells, sponges as well as folded away paper. Slip outer wrappers rear in and remain the particular magnets part towards the butt. If your wrapper is one which needs to be ripped open dissect it meticulously. Following the particular candy, complete the particular wrapper with the filling, next adhesive the particular wrapper rear in. These magnets can be created through small containers regarding candies, nicotine gum wrappers, perfect pots and similar things. A tiny permanent magnetic sq . for the rear is all it takes to keep the crooks to the particular fridge and other metallic regions.
Under Armour Curry Speedform Apollo http://www.okfreeshipping.com/2017-new-arrival-under-armour-curry-speedform-apollo-men-red.html

Under Armour Curry 16月 7th, 2017 at 1:50 PM

My partner and i didn adore carrying a child. If only I really could tell you just how I was one of those women who glowed and also ended up being clearly supposed to hold infants and turn into far more beautiful and also happy than in the past. Not so much. 3 child birth around 8 years, just about all perfectly balanced entire time period infants, every one brought on as a result of how to get started without any help although not actually getting out of the actual door pertaining to dilation, every one primary me to gain specifically Forty two kilos regardless how much as well as minor exercising, every sent without having a csection nevertheless certainly with an epidural.
Under Armour Curry 1 http://www.sohiking.com/outlet-under-armour-curry-1-men-black-gold-red.html

salomon speedcross 3 cs womens6月 10th, 2017 at 4:20 PM

KKLA Sports Apparel Denver colorado., Incorporated ended up being founded within Two thousand within ZeJiang, Cina. Currently it’s 12 side branch organizations around Cina. We’re an international wholesaler / retailer regarding Sports Apparel (Icehockey Hat,Football Hat,soccer Hat,Soccer Hat,Baseball Hat). Our company includes design and style, develop, create, sale made and service. We now have greater than Some skilled producers for your personal merchandise. And there’s tiny order for you, Cheapest price and finest support. Permit become close friends and also company lover. Wear wait to get hold of here if you’d like anytime. There exists a position whenever new jobless statements may stop simply because everyone can have lost their own work. As of this response, numerous my colleagues have lost their own work as a result of money grubbing leading degree managers and also management. More are going to be let go over the following calendar month. Numerous inside my palce of labor are generally worrying how the entire center may failure over the following 12 months. What is depressing is that this company has become successful. Sure, our company has already established good and bad together with the economic climate, however we have always (and are) really lucrative. Professionals obviously insist that people must scale back, merge and many others. due to these a down economy. Effectively, the people who been employed from our center must not become facing a down economy since it has been a very good company. Currently most are going to need to gather unemployment simply because business goofs think that immeasureable bucks within annual earnings are too few.
salomon speedcross 3 cs womens http://www.forsalomon.com/cheap-j0018-salomon-speedcross-3-cs-womens-trail-running-shoes-blue-pink.html

customize curry 16月 10th, 2017 at 4:51 PM

If you’d prefer to be able to ingest but desire to stop as well as add seem to have to be able to willpowerto achieve this,it can be simply because chemicals inside your brainare letting you know to acquire yet another pint, a new study indicates.
customize curry 1 http://www.newsalomonline.com/under-armour-clearance/online-sale-ua-curry-1-discount.html

buy salomon skis6月 17th, 2017 at 7:50 PM

Do not be tempted to buy from jewellery retailers available for sale. Running a business areas, there are several jewellery retailers that induce buyers for you to action a foot inside store by inserting massive “We’re in SALE” indicators. A few this kind of jewellery retailers margin the prices ahead of the purchase and lower price them during the purchase time period to make sure that that they acquire any tidy income. Thus, until you have already been seeking that diamond ring with regard to a few months and understand its price draw off by heart, wait to purchase this available for sale.
buy salomon skis http://www.justfootzone.com/outlets-y503-salomon-speedcross-3-cs-mens-trail-running-shoes-apple-green-black.html

sport shop6月 30th, 2017 at 1:17 AM

How should we squeeze joy into our own sex-life if we
sport shop http://www.latestsalomon.com/salomon-extend-go-to-snow-gearbag-4-cheap-salomon-1057.html

converse skate shoes7月 2nd, 2017 at 2:58 AM

Sneakers, unlike a great many other sneakers, are employed through much more literally lively individuals similar to players. Additional sneakers that are not used frequently get odiferous smell in the long run. Yet sneakers get odiferous almost ultimately after a couple of employs. To create things more serious, sneakers cannot be included the actual washer and stay machinedried. Guide book cleaning should be used if you want to maintain pair of sneakers sensing fresh. The catch is, you cannot do that all the time. There are easier treatments to the difficulty and a few of those tend to be included below:
converse skate shoes http://www.okfreeshipping.com/outlet-converse-shoes-white-love-heart-beats-womens-classic-high-cheap-sale.html

Leave a comment

Your comment


Trackback URL