原諒我的即將到來的問題,哈哈。 (在此非常新)codeigniter寧靜的網絡服務+數據庫查詢
我已閱讀。
我已經通過編輯autoload.php文件設置了自動連接到數據庫。
我正在創建自己的控制器,名爲dsapi.php(代碼如下),我想要ad_get()
函數從我的簡單數據庫中檢索所有數據,以便我可以在我開發的android應用程序中使用它。
我看了一下 this guidelines page並試圖寫一些東西,但即時通訊很漂亮,正如你所看到的。我甚至接近我想要的嗎?
class dsapi extends REST_Controller {
function ad_get()
{
**$query = $this->db->query('SELECT index, title, detailed FROM ads');
foreach ($query->result_array() as $row)
{
echo $row['index'];
echo $row['title'];
echo $row['detailed'];
}
$this->response($query, 200);**
}
function ad_put()
{
// create a new user and respond with a status/errors
}
function ad_post()
{
// update an existing user and respond with a status/errors
}
function ad_delete()
{
// delete a user and respond with a status/errors
}
}
你有什麼想做的事:'echo'值或歸還?你的'ad_get()'這樣做:1.檢索數據,2.回顯數據,3.返回*查詢資源*(不是數據!)作爲響應。我認爲你需要[單獨命令和查詢](http://en.wikipedia.org/wiki/Command-query_separation) – scriptin