将视图中的 db 数据返回给 doophp
Posted
技术标签:
【中文标题】将视图中的 db 数据返回给 doophp【英文标题】:Return db data in view to doophp 【发布时间】:2012-11-04 18:20:51 【问题描述】:我想问 doophp 我可以通过什么方式将我的数据库数据从模型控制器返回到我的视图。
这是我的控制器:
`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>`
【问题讨论】:
你做了什么?在您的问题中添加一些代码示例和更多详细信息。 您能帮忙查看我的数据库数据吗? 如果你想为你的问题添加细节,你可以edit
它。不要在评论部分写它是不可读的。我已经为你完成了这项工作。
对不起,你现在能帮我吗...??
【参考方案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>`
【讨论】:
以上是关于将视图中的 db 数据返回给 doophp的主要内容,如果未能解决你的问题,请参考以下文章