【发布时间】:2014-10-13 18:10:37
【问题描述】:
我在使用 Silverstripe CMS 时遇到问题。
我有基本的 SQL 查询,我想在<ul><li> 菜单中显示哪些结果。这应该很容易,但我在浏览文档时失败了。我发现了一些更复杂的示例(项目、学生),但在我看来,应该存在一些更简单的方法来做到这一点。谁能帮忙或者给我一个提示?
总结一下:我想运行一个 db sql 查询并将数据显示为列表。
我的WishPage.php
class WishPage extends Page {
// some code which is irrelevant for this matter, but works fine
}
class WishPage_Controller extends Page_Controller {
private static $allowed_actions = array('AddNewWishForm');
public function AddNewWishForm() {
// here you can add data to db
}
// Now I would like to show it; and here is the problem.
public function ShowWishList() {
$records = DB::query ("SELECT Title FROM Wishes;");
return $records;
}
}
我的模板WishPage.ss
<% include SideBar %>
<div class="content-container unit size3of4 lastUnit">
<div id="WishForm">
<h2>Try it</h2>
$AddNewWishForm
</div>
</div>
更新
我的Wishes.php
<?php
class Wishes extends DataObject {
private static $db = array(
'Name' => 'Text',
'Comment' => 'Text'
);
}
【问题讨论】:
标签: php silverstripe