最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

攻克CakePHP(PHP中的Ruby On Rails框架)圖文介紹第2/2頁

 更新時間:2008年10月22日 21:56:58   作者:  
CakePHP框架實例介紹分析。圖文并茂

增加Cotroller模塊:

app/controllers/posts_controller.php

代碼:

<?php

require_once ('cake/app_controller.php');

class PostsController extends AppController {

    
public $name = 'Posts';

    
function index()
    {
          
$this->set('posts', $this->Post->findAll());
    }

    
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');
                $this->redirect("/posts/index");
            }
        }
    }
    
    
function delete($id)
    {
        
$this->Post->del($id);
        
//$this->flash('The post with id: '.$id.' has been deleted.', '/posts');
        $this->redirect("/posts/index");
    }
    
    
function edit($id = null)
    {
        
if (empty($this->data))
        {
            
$this->Post->id = $id;
            
$this->data = $this->Post->read();
        }
        
else
        {
            
if ($this->Post->save($this->data['Post']))
            {
                
//$this->flash('Your post has been updated.','/posts');
                $this->redirect("/posts/index");
            }
        }
    }
}

?>

增加頁面模塊:

/app/views/下追加posts文件夾,然后再添加4個頁面(一般后綴為.rhtml)

代碼依次為:

index.thtml

<h1>Blog posts</h1>
<p><?php echo $html->link("Add Post", "/posts/add"); ?>
<table>
    
<tr>
        
<th>Id</th>
        
<th>Title</th>
        
<th>Created</th>
    
</tr>

   
<!-- Here's where we loop through our $posts array, printing out post info -->

    
<?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>

view.thtml

<h1><?php echo $post['Post']['title']?></h1>

<p><small>Created: <?php echo $post['Post']['created']?></small></p>

<p><?php echo $post['Post']['body']?></p>

<br>

<p><?php echo $html->link('Return', '/posts/index/');?></p>

edit.thtml

<h1>Edit Post</h1>
<form method="post" action="<?php echo $html->url('/posts/edit')?>">
    
<?php echo $html->hidden('Post/id'); ?>
    
<p>
        Title:
        
<?php echo $html->input('Post/title', array('size' => '40'))?>
        
<?php echo $html->tagErrorMsg('Post/title', 'Title is required.') ?>
    
</p>
    
<p>
        Body:
        
<?php echo $html->textarea('Post/body', array('rows'=>'10')) ?>
        
<?php echo $html->tagErrorMsg('Post/body', 'Body is required.') ?>
    
</p>
    
<p>
        
<?php echo $html->submit('Save') ?>
    
</p>
</form>

add.thtml

<h1>Add Post</h1>
<form method="post" action="<?php echo $html->url('/posts/add')?>">
    
<p>
        Title:
        
<?php echo $html->input('Post/title', array('size' => '40'))?>
        
<?php echo $html->tagErrorMsg('Post/title', 'Title is required.') ?>
    
</p>
    
<p>
        Body:
        
<?php echo $html->textarea('Post/body', array('rows'=>'10')) ?>
        
<?php echo $html->tagErrorMsg('Post/body', 'Body is required.') ?>
    
</p>
    
<p>
        
<?php echo $html->submit('Save') ?>
    
</p>
</form>

測試URL: http://localhost/phpblog/posts/
參考網(wǎng)頁:http://manual.cakephp.org/appendix/blog_tutorial
以下是CakePHP框架的一些特性: http://www.lostk.com/blog/cakephp_note/

e="COLOR: #000000">
        Title:
        <?php echo $html->input('Post/title', array('size' => '40'))?>
        
<?php echo $html->tagErrorMsg('Post/title', 'Title is required.') ?>
    
</p>
    
<p>
        Body:
        
<?php echo $html->textarea('Post/body', array('rows'=>'10')) ?>
        
<?php echo $html->tagErrorMsg('Post/body', 'Body is required.') ?>
    
</p>
    
<p>
        
<?php echo $html->submit('Save') ?>
    
</p>
</form>

測試URL: http://localhost/phpblog/posts/
參考網(wǎng)頁:http://manual.cakephp.org/appendix/blog_tutorial
以下是CakePHP框架的一些特性: http://www.lostk.com/blog/cakephp_note/

相關(guān)文章

最新評論

遂宁市| 滨海县| 云南省| 柳林县| 泗阳县| 彭泽县| 卢氏县| 泗水县| 甘南县| 上饶县| 金门县| 珠海市| 铜陵市| 开化县| 新建县| 塘沽区| 革吉县| 东兴市| 永康市| 阿图什市| 无极县| 永寿县| 鹿邑县| 乌拉特后旗| 莲花县| 青海省| 岱山县| 同心县| 宜都市| 皮山县| 寻乌县| 凤庆县| 浠水县| 永靖县| 滕州市| 拉萨市| 晋中市| 芦溪县| 韶关市| 会东县| 泽库县|