【问题标题】:Cakephp 2.1 - AjaxHelperCakephp 2.1 - AjaxHelper
【发布时间】:2012-04-21 15:07:42
【问题描述】:

我正在使用 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>

这是我尝试使用 ajaxHelper 自动完成 Department.name 的 add.ctp 文件。

在我的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, line 84] 致命错误:在第 84 行对 C:\xampplite\htdocs\cakephp\app\View\Employees\add.ctp 中的非对象调用成员函数 autoComplete()

【问题讨论】:

    标签: cakephp cakephp-2.1 cakephp-ajaxhelper


    【解决方案1】:

    假设您已将助手添加到控制器的 $helpers 数组中,您必须使用 $this-&gt;Ajax-&gt;autoComplete() 而不是 $ajax-&gt;autoComplete() 访问助手。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-31
      • 2012-05-12
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      相关资源
      最近更新 更多