CakePHP2.1-AjaxHelper
我使用的是cakePhp的最新(2.1.1)版本。 我试图实现ajaxHlper()。但是夹在中间CakePHP2.1-AjaxHelper,cakephp,cakephp-2.1,cakephp-ajaxhelper,Cakephp,Cakephp 2.1,Cakephp Ajaxhelper,我使用的是cakePhp的最新(2.1.1)版本。 我试图实现ajaxHlper()。但是夹在中间 <head> <script type="text/javascript"> $(document).ready(function(){ $("#EmployeeAddForm").validate(); }); </script> </head> <div cla
<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>
它不起作用了。我可能犯了什么错误?
它给了我以下错误:
注意(8):未定义变量:ajax[APP\View\Employees\add.ctp,第84行]
致命错误:在第84行的C:\xamplite\htdocs\cakephp\app\View\Employees\add.ctp中对非对象调用成员函数autoComplete()假设已将助手添加到控制器的
$helpers
数组中,则必须使用$this->Ajax->autoComplete()访问助手
而不是$ajax->autoComplete()
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';
}