CakePHP Start
FrontPageFindPageTitleIndexRecentChangesUserPreferences UserPreferences E D R S I M H RSS

Contents

1 CakePHPStart
1.1 Installing CakePHP
1.1.1 ¿ä±¸»çÇ×
1.1.2 ¼³Ä¡
1.2 Å×½ºÆ® ÆäÀÌÁö ¸¸µé±â
1.2.1 DB »ý¼ºÇϱâ
1.2.2 Cake µ¥ÀÌŸº£À̽º ¼¼ÆÃ
1.2.3 Crate a Post Model
1.2.4 Create Posts Controller
1.2.5 Create Post Views
1.2.6 Routes ¼¼ÆÃÇϱâ
1.2.7 ·¹À̾ƿô ¼¼ÆÃÇϱâ
1.3 Âü°í

1 CakePHPStart #

  • Windowsȯ°æ¿¡¼­ CakePHP ¸¦ µ¹¸®±â À§ÇÑ °£´ÜÇÑ ¼³¸í¼­
  • http:/manual.cakephp.org¿¡ ÀÖ´Â ºí·Î±× Æ©Å丮¾óÀ» º¸±¸ ½ÇÀç·Î Àû¿ëÇÏ´Â °úÁ¤¿¡¼­ Çì¸Þ´Â ºÎºÐÀÌ À־ º¸±â ½±°Ô ¾Ë¼öÀÖ°Ô Áß¿äÇÑ ºÎºÐ¸¸ Á¤¸®ÇÞ´Ù.

1.1 Installing CakePHP #

1.1.1 ¿ä±¸»çÇ× #

  • HTTP¼­¹ö / PHP4 ÀÌ»ó
  • µ¥ÀÌŸº£À̽º (MySQL µîµî)

  • APMÆÐŰÁö¸¦ ´Ù¿î¹Þ¾Æ ¼³Ä¡ÇÑ´Ù( http://www.apmsetup.com )

1.1.2 ¼³Ä¡ #

1.2 Å×½ºÆ® ÆäÀÌÁö ¸¸µé±â #

1.2.1 DB »ý¼ºÇϱâ #

  • cake¶ó´Â µ¥ÀÌŸº£À̽º¸¦ ¸¸µç´Ù
  • µ¥ÀÌŸº£À̽º¿¡ Å×À̺íÀ» Á¦ÀÛÇÏ´Â Äõ¸®¸¦ ¿äûÇÑ´Ù
    /* 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());
    

1.2.2 Cake µ¥ÀÌŸº£À̽º ¼¼ÆÃ #

  • /app/config/database.php.default¸¦ º¹»çÇØ¼­ database.php¶ó´Â À̸§ÀÇ phpÆÄÀÏÀ» ¸¸µç´Ù.
  • ÆÄÀÏÀ» ¿­¾î µ¥ÀÌŸº£À̽º ¼¼ÆÃÀ» ÇÑ´Ù
    <?php
    class DATABASE_CONFIG {
    
    	var $default = array(
    		'driver' => 'mysql',
    		'connect' => 'mysql_connect',
    		'host' => 'localhost',
    		'login' => 'root',
    		'password' => 'apmsetup',
    		'database' => 'cake', 
    		'prefix' => '' 
    	);
    }
    ?
    
  • ÀͽºÇ÷η¯¿¡¼­ http://localhost/cake/app ÆäÀÌÁö¸¦ ¿­¾úÀ»¶§ÀÇ ´ÙÀ½°ú °°Àº ¸Þ½ÃÁö°¡ ³ª¿À¸é DB ¼¼ÆÃÀÌ ÀßµÈ °ÍÀÌ´Ù
    Your database configuration file is present. 
    
    Cake is able to connect to the database.
    


1.2.3 Crate a Post Model #

  • /app/models/post.php¸¦ ¸¸µç´Ù
    <?php
    
    class Post extends AppModel
    {
        var $name = 'Post';
    }
    
    ?>
     

1.2.4 Create Posts Controller #

  • /app/controllers/posts_controller.php¸¦ ¸¸µç´Ù
    <?php
    
    class PostsController extends AppController
    {
        var $name = 'Posts';
    
        function index()
        {
            $this->set('posts', $this->Post->findAll());
        }
    }
    
    ?>
     

1.2.5 Create Post Views #

  • /app/views/posts/index.thtmlÀ» ¸¸µç´Ù( htmlÀÌ ¾Æ´Ï¶ó thtmlÀÓ)
    <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
     

1.2.6 Routes ¼¼ÆÃÇϱâ #

  • Routes¸¦ ¼¼ÆÃÇØ¾ß http://localhost/app ¶ó°í¸¸ Ãĵµ ³»°¡ Á¦ÀÛÇÑ À¥ÆäÀÌÁö¿¡ Á¢±ÙÀÌ µÈ´Ù
  • /app/config/routes.php¸¦ ¿­°í ´ÙÀ½ ¹®ÀåÀ» »èÁ¦ ÇÑ´Ù
    $Route->connect ('/', array('controller'=>'pages', 'action'=>'display', 'home'));
     
  • ±×¸®°í ´ÙÀ½ ¹®ÀåÀ» »ðÀÔÇÑ´Ù( PostsControllerÀÇ indexÇÔ¼ö¸¦ ÁöÁ¤ÇÏ´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù)
    $Route->connect ('/', array('controller'=>'posts', 'action'=>'index'));
     
  • ÀͽºÇ÷η¯¿¡¼­ http://localhost/cake/app ÆäÀÌÁö¸¦ ¿¬´Ù. ´ÙÀ½°ú °°Àº ³»¿ëÀÌ Æ÷Ç﵂ ÀÖÀ¸¸é ¼º°øÀÌ´Ù
    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 
     

1.2.7 ·¹À̾ƿô ¼¼ÆÃÇϱâ #

  • ¾ÆÁ÷ header¿Í footer¸¦ ¼¼ÆÃ¾ÈÇ߱⠶§¹®¿¡ ³»°¡ ¼³Á¤¾ÈÇÑ È­¸é¿¬ÃâÀÌ º¸ÀÏ °ÍÀÌ´Ù
  • cake/libs/view/templates/layouts/¿¡¼­ default.thtmlÆÄÀÏÀ» app/views/layouts¿¡ º¹»çÇÑÈÄ ¼öÁ¤ÇÏ¸é µÈ´Ù
    <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">
    			&nbsp;
    				<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: ¿©±â´Ù ÆäÀÌÁö ÇÏ´ÜÀ» ¿¬Ãâ 
     

1.3 Âü°í #


EditTextFindPageDeletePageLikePages Valid XHTML 1.0! Valid CSS! powered by MoniWiki