我需要知道为什么以下不起作用.这段代码将从索引控制器中提取数据以搜索获取json数据.任何请求都没有发生且没有任何反应
我是Cakephp 3.0的新手
我正在尝试在CakePHP 3.0中使用自动完成/自动建议,但我发现的所有内容都是1.3或者不是Cake,我不知道该怎么做才能让它正常工作.我正是需要它为cakephp 3.0 snippet 1.CarsController.php这是carcontroller访问时ajax请求并将在json数据中编码2.CarsTable.php从carstable中获取数据3.index.ctp是视图页面和自动完成方法
<?php
namespace App\Controller;
use App\Controller\AppController;
class CarsController extends AppController {
public function index() {
$this->loadComponent('RequestHandler');
if ($this->request->is('ajax')) {
$term = $this->request->query('term');
$carNames = $this->Car->getCarNames($term);
$this->set(compact('carNames'));
$this->set('_serialize', 'carNames');
}
}
}
?>Run Code Online (Sandbox Code Playgroud)
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class Carstable extends AppModel {
public function getCarNames ($term = null) {
if(!empty($term)) {
$cars = $this->find('list', array(
'conditions' => array(
'name LIKE' => trim($term) . '%'
)
));
return $cars;
}
return false;
}
} …Run Code Online (Sandbox Code Playgroud)