我正在使用 cakePhp 的最新(2.1.1)版本。我试图实现 ajaxHlper( http://www.cakephp.4uk.pl/ ) 。但夹在中间。
<head>
<script type="text/javascript">
$(document).ready(function(){
$("#EmployeeAddForm").validate();
});
</script>
</head>
<div class="employees form">
<?php echo $this->Form->create('Employee');?>
<fieldset>
<legend><?php echo __('Add Employee'); ?></legend>
<?php
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
//echo $this->Form->input('age');
echo $this->Form->input('age', array('class' => 'required number'));
echo $this->Form->input('sex');
echo $this->Form->input('Adress.first_line');
echo $this->Form->input('Adress.second_line');
echo $this->Form->input('Adress.city');
echo $this->Form->input('Adress.state');
echo $ajax->autoComplete('Department.name', '/ajax/autoComplete')
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Employees'), array('action' => 'index'));?></li>
<li><?php echo $this->Html->link(__('List Adresses'), array('controller' => 'adresses', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Adress'), array('controller' => 'adresses', 'action' => 'add')); ?> </li>
</ul>
这是我的 add.ctp 文件,其中 Department.name 我正在尝试使用 ajaxHelper 自动完成。
在我的EmployeesController.php中,我有自动完成功能,就像
function autoComplete() {
echo $this->params['url']['q'] . "---";
$this->loadModel("Department");
$this->set('departments', $this->Department->find('all', array(
'conditions' => array(
'Department.name LIKE ' => '%'.$this->params['url']['q'].'%'
),
'limit' => $this->params['url']['limit'],
'fields' => array('name')
)));
$this->layout = 'ajax';
}
它不工作。我正在做的错误可能是什么?它给了我以下错误:
注意(8):未定义变量:ajax [APP\View\Employees\add.ctp,第 84 行] 致命错误:在 C:\xampplite\htdocs\cakephp\app 中对非对象调用成员函数 autoComplete()第 84 行的 \View\Employees\add.ctp