Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Codeigniter中创建Restful API?_Php_Rest_Api_Codeigniter - Fatal编程技术网

Php 如何在Codeigniter中创建Restful API?

Php 如何在Codeigniter中创建Restful API?,php,rest,api,codeigniter,Php,Rest,Api,Codeigniter,我在尝试我制作的API时遇到问题。当我在《邮递员》上测试它时,它看起来是假的,尽管我的用户名和密码是正确的。你能找出我的代码的问题吗? 我真的很感谢你的帮助 Auth_admin.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); require APPPATH . '/libraries/REST_Controller.php'; class Auth_admin extends RES

我在尝试我制作的API时遇到问题。当我在《邮递员》上测试它时,它看起来是假的,尽管我的用户名和密码是正确的。你能找出我的代码的问题吗? 我真的很感谢你的帮助

Auth_admin.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

require APPPATH . '/libraries/REST_Controller.php';

class Auth_admin extends REST_Controller
{
    public function signin_post()
    {
        $this->load->model('model_admin', 'admin');
        $params = array(
                'username' => $this->post('username'),
                'password' => md5($this->post('password'))  
    );
    $result = $this->admin->admin_check($params);
    if ($result){
        if ($result->level == "admin"){

            $response   = array(
                "status"    => true,
                "message"   => "Authentication seccessfully",
                "auth"      => array(
                    "username"  => $result->username
                )
            );
            $this->set_response($response, REST_Controller::HTTP_OK);
        }else{
            $response   = array(
                "status"    => false,
                "message"   => "This features does'nt exist for your Account"
            );
            $this->set_response($response, REST_Controller::HTTP_OK);
        }
    }
}
    }
<?php

class Model_admin extends CI_Model
{
    var $tablename;

    public function __construct()
    {
        parent::__construct();
        $this->tablename    = "m_admin";
    }

    public function admin_check($data = array())
    {
        $params = array(
            'username' => $data['username'],
            'password' => $data['password'],
        );
        $this->db->where($params);
        $query  = $this->db->get($this->tablename);
        return $query->row();
    }

}

必须在控制器名称之后传递函数名称

喜欢你的道路:它会成功的


如果这不起作用,请添加
index.php
并检查它,因为这取决于您如何设置项目。

请不要使用自己的密码哈希,特别是不要使用MD5()或SHA1()。为了用户的安全,PHP提供并请使用它们。我相信Codeigniter也提供了一些正确的方法,从img中我可以看到您正在调用类Auth_admin的索引函数,它不会像我忘了什么一样存在。谢谢你的帮助。我很感激。