webroot
/cake
/app
/cake
/docs
/vendors
/* First, create our posts table: */
CREATE TABLE posts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50),
body TEXT,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);
/* Then insert some posts for testing: */
INSERT INTO posts (title,body,created)
VALUES ('The title', 'This is the post body.', NOW());
INSERT INTO posts (title,body,created)
VALUES ('A title once again', 'And the post body follows.', NOW());
INSERT INTO posts (title,body,created)
VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'root',
'password' => 'apmsetup',
'database' => 'cake',
'prefix' => ''
);
}
?
Your database configuration file is present. Cake is able to connect to the database.
<?php
class Post extends AppModel
{
var $name = 'Post';
}
?>
<?php
class PostsController extends AppController
{
var $name = 'Posts';
function index()
{
$this->set('posts', $this->Post->findAll());
}
}
?>
<h1>Blog posts</h1> <table> <tr> <th>Id</th> <th>Title</th> <th>Created</th> </tr> <?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']); ?> </td> <td><?php echo $post['Post']['created']; ?></td> </tr> <?php endforeach; ?> </table
$Route->connect ('/', array('controller'=>'pages', 'action'=>'display', 'home'));
$Route->connect ('/', array('controller'=>'posts', 'action'=>'index'));
Blog posts Id Title Created 1 The title 2007-10-12 00:11:43 2 A title once again 2007-10-12 00:11:43 3 Title strikes back 2007-10-12 00:11:43
<body>
<div id="container">
<div id="header">
<h1>header: ¿©±â´Ù ÆäÀÌÁö »ó´ÜÀ» ¿¬Ãâ </h1>
</div>
<div id="content">
<?php if ($session->check('Message.flash'))
{
$session->flash();
}
echo $content_for_layout;
?>
</div>
<div id="footer">
<h3>footer: ¿©±â´Ù ÆäÀÌÁö ÇÏ´ÜÀ» ¿¬Ãâ </h3>
</a>
</div>
</div>
<?php echo $cakeDebug?>
</body>
header: ¿©±â´Ù ÆäÀÌÁö »ó´ÜÀ» ¿¬Ãâ Blog posts Id Title Created 1 The title 2007-10-12 00:11:43 2 A title once again 2007-10-12 00:11:43 3 Title strikes back 2007-10-12 00:11:43 footer: ¿©±â´Ù ÆäÀÌÁö ÇÏ´ÜÀ» ¿¬Ãâ