0

请原谅我即将提出的问题,大声笑。(我对此非常陌生)

我已阅读本教程

我已经通过编辑 autoload.php 文件设置了自动连接到数据库。

我正在创建自己的控制器,称为 dsapi.php(代码如下),我希望该ad_get()函数从我的简单数据库中检索所有数据,以便可以在我开发的 android 应用程序中使用它。

我查看了 此指南页面并尝试写一些东西,但如您所见,我很无能为力。我什至接近我想要的?

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
    }
}
4

1 回答 1

0

模型 和代码示例的视频教程描述

 class Blogmodel extends CI_Model 
 {
 var $title   = '';
 var $content = '';
 var $date    = '';

 function __construct()
 {
     // Call the Model constructor
     parent::__construct();
 }

 function get_last_ten_entries()
 {
     $query = $this->db->get('entries', 10);
     return $query->result();
 }

 function insert_entry()
 {
     $this->title   = $_POST['title']; // please read the below note
     $this->content = $_POST['content'];
     $this->date    = time();

     $this->db->insert('entries', $this);
 }

 function update_entry()
 {
     $this->title   = $_POST['title'];
     $this->content = $_POST['content'];
     $this->date    = time();

     $this->db->update('entries', $this, array('id' => $_POST['id']));
 }}
于 2012-06-12T15:54:09.117 回答