尝试使用cakephp在我的服务器中显示信息时出错

时间:2013-10-11 18:34:16

标签: php sql cakephp

我正在使用cakephp。我的cakephp版本是v 0.2.9

我想在显示模块内容BlackList时遇到问题。当我想在浏览器中显示它时,我有以下错误消息:

{"blacklist":"failed"}

我有数据库连接,但是当我编写localhost / claro / getBlacklist时,我需要在黑名单中显示信息。

我认为我在模型或控制器中有错误,感谢您的帮助,谢谢。

我的控制器是:

public function getBlacklist() 
    {
        if(isset($this->params['url']["number"])) {
            $number = $this->params['url']["number"];
            $blacklist = $this->Blacklist->findNumber($number);
        } else {
            $blacklist = "failed";
        }

        $this->set('blacklist', $blacklist);
        $this->layout = 'ajax';
    }

黑名单模型是:

<?php

App::uses('AppModel', 'Model');

class Blacklist extends AppModel {
    public $name = 'Blacklist';



    public function findNumber($number) {
        $params = array(
                    'conditions' => array('number' => $number)
                    );


        $res = $this->find('first', $params);

        return $res;
    }


    public function getList() {
        $query = $this->find('all');

        return $query;
    }   


    public function addNumber($data) {
        $sql = "INSERT INTO blacklists VALUE('', '" . $data["number"] . "')";
        $query = $this->query($sql);

        return $this->id;
    }

    public function vaciar() {
        $sql = "DELETE FROM blacklists where 1";
        $query = $this->query($sql);

        return 1;
    }

    public function deleteNumbers($info) {
        $sql = "DELETE FROM blacklists WHERE id IN ($info)";
        $query = $this->query($sql);

        return 1;
    }

}

?>

我的AdminController是:

public function getBlack() {
        $black = $this->Blacklist->getList();
        $this->set('black', $black);
        $this->layout = 'ajax';
    }


    public function addBlack() {
        if(isset($this->params['url']["number"])) {
            $badd = $this->Blacklist->addNumber($this->params['url']);
        } else {
            $badd = "failed";
        }

        $this->set('badd', $badd);
        $this->layout = 'ajax';
    }

public function deleteBlack() {
        if(isset($this->params['url']["info"])) {
            $delblack = $this->Blacklist->deleteNumbers($this->params['url']["info"]);
        } else {
            $delblack = "failed";
        }

        $this->set('delblack', $delblack);
        $this->layout = 'ajax';
    }

    public function vaciarBlack() {
        $bvaciar = $this->Blacklist->vaciar();
        $this->set('bvaciar', $bvaciar);
        $this->layout = 'ajax';
    }

0 个答案:

没有答案