返回db数据以查看doophp

时间:2012-11-04 18:20:52

标签: database view doophp

我想问doophp,我可以用什么方式将我的数据库数据从模型控制器返回到我的视图。

这是mycontroller:

`class CategoryController extends DooController { 
    public function Index(){ 
        Doo::loadModel('Category'); 
        $category = new Category; 
        Doo::db()->find( $category, array('limit'=>1) ); 
        $this->view()->render('Category/Index', $category); 
    } 
} 

我有一个像这样的视图(category.html):

<!DOCTYPE html> 
<html> 
    <head> 
        <title></title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    </head> 
    <body> 
        <div>{{category.categoryname}}</div> 
    </body> 
</html>`

1 个答案:

答案 0 :(得分:1)

最简单的方法是:

class CategoryController extends DooController { 
    public function Index(){ 
        Doo::loadModel('Category'); 
        $category = new Category; 
        Doo::db()->find( $category, array('limit'=>1) ); 
        $this->view()->renderc('Category/Index', array("category" => $category)); 
    } 
}

然后是category.php

<!DOCTYPE html> 
<html> 
    <head> 
        <title></title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    </head> 
    <body> 
        <div><?php echo $this->data['category']->categoryname; ?></div> 
    </body> 
</html>`