CakePHP 2.2中的连接已重置问题

时间:2012-07-17 10:16:33

标签: php cakephp cakephp-2.1

我是cakephp的新手,当我试图根据状态制作动态下拉城市列表然后我收到此错误

The connection was reset.

我的js代码是

$(document).ready(function(){
$('#UserState').change(function(){
  var stateid=$(this).val();
  $.ajax({
  type: "POST",
  url: "checkcity",
  data:'stateid='+stateid+'&part=checkcity',
  success: function(data) {
  $("#city_div").html(data);
  }
  });
});
});

为此我在用户控制器上使用功能检查。这是我的用户控制器文件。

 class UsersController extends AppController {
 public $uses=array('User', 'City','State');
 function index(){

  }
  public function add() {

    $this->set('states_options', $this->State->find('list', array('fields' =>array('id','name') )));
$this->set('cities_options', array());
    if ($this->request->is('post')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

public function checkcity(){
$this->layout=false;
$stateid=$this->request->data['stateid'];
$this->set('cities_value',$this->City->find('list', array('conditions' =>    array('state_id' => $stateid), 'fields' => array('id', 'name')));
}
}  

现在我把这一行放在我的控制器文件中

       $this->set('cities_value',$this->City->find('list', array('conditions' =>    array('state_id' => $stateid), 'fields' => array('id', 'name')));

然后我得到这个错误。谁能告诉我它的问题是什么?

1 个答案:

答案 0 :(得分:2)

我想,你错过了一个结束。请检查它是否不适合您。 它应该是:

$this->set('cities_value',$this->City->find('list', array('conditions' =>    array('state_id' => $stateid), 'fields' => array('id', 'name'))));