CakePHP 2.5自动完成

时间:2014-06-18 22:32:23

标签: php ajax cakephp autocomplete

我一直在关注教程以获得基本的自动填充表格,但出于某种原因,无论我输入什么,它都会变回空白。

这是我的代码 这是我的 StarsController.php

<?php

class StarsController extends AppController
{
    var $name = "Stars";

    function Auto()
    {
        $names = '';
        $this->set('names', $names);
    }

    function find()
    {
        $this->Star->recursive = -1;
        if($this->request->is('ajax'))
        {
            $this->autoRender = false;
            $this->layout = 'ajax';
            $results = $this->Star->find('all');
            $names = Set::extract('../stars/Auto', $results);
            echo json_encode($names);
        }
    }
}
?>

这是我的 auto.ctp 视图文件

<div class="search form">
<fieldset>
<legend></legend>
<?
        $this->Paginator->options(array('url' => $this->passedArgs));
        $this->Form->create('Star', array('type'=>'post','action' => 'find'));

        echo $this->Form->input('star', array(
            'empty' => 'Enter name',
            'label' => 'Name',
            'option'=> $names,
            'id' => 'star',
            'autocomplete' => 'on'));
        echo $this->Form->end(__('Search'));

        ?>

    </fieldset>
</div>
<script>
$( "#star" ).autocomplete({
  source: "/star/find",
  minLength: 2,
  delay: 2
});
</script>

我的数据库设置

CREATE TABLE `stars` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  `name` varchar(100) COLLATE latin1_general_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1405382401 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1405382401 ;

有人能看出为什么控制器没有收到数据吗?

0 个答案:

没有答案
相关问题