0

帮我修复 isPut 或 isPost 以保存逻辑,在下面的代码中,我可以查看 from 中的数据,但是当我尝试保存它时它不起作用,我尝试过 ispost 和 isput 逻辑都不起作用。我认为问题在于控制器部分没有视图这里是我的表单视图,

<?php 

    echo $this->Form->create('Role',array('url'=>array('controller'=>'Organisations','action' => 'edit_profile'),'id' => 'role'));
    echo $this->Form->input('RoleLanguage.rolename',array('label'=>'Profile Name:','id'=>'rolename'));

    $options = array('A' => 'Approve', 'P' => 'Pending', 'D' => 'Delete');
    echo $this->Form->input('Role.status', array(
    'options'=>$options,
    'empty' => false,
    'label'=>'Status',
     'style'=>'width:100px',

    'id'=>'status'
    ));
    $id= array('value' => $id);
    //print_r($id);die();
    echo $this->Form->hidden('rle_id', $id);
    echo "<br>";
    $options = array('R' => 'Role', 'P' => 'Position', 'T' => 'Team','C'=>'Core Strategic Profile');

     echo $this->Form->input('Role.type', array(
    'options'=>$options,
    'empty' => false,
    'label'=>'Type of Job Profile:',
     'style'=>'width:100px',

    'id'=>'type'
    ));
      echo "<br>";
      echo $this->Form->input('RoleLanguage.external_document_URL',array('label'=>'External Document URL:','id'=>'external_document_URL','type'=>'text'));
      echo "<br>";
      echo $this->Form->input('RoleLanguage.description', array('style'=>'width:420px','rows' => '5', 'cols' => '5','label'=>'Description','id'=>'description'));

    ?>

这是控制器逻辑

function edit_profile($id=NULL)
{
     $this->layout='Ajax'; 

         //print_r($id);die();
         $this->set('id',$id); 
                $this->Role->recursive = 0;     
                $this->Role->id = $id;
                $language = $this->getLanguage('content');
                $this->Role->unBindModel(array("hasMany" => array('RoleLanguage')));
                $this->Role->bindModel(array("hasOne" => array('RoleLanguage'=> array('foreignKey' => 'rle_id', 'className' => 'RoleLanguage', 'type' => 'INNER', 'conditions' => array('RoleLanguage.language' => $language)))));

                $this->data = $this->Role->read();

                //print_r($this->data);die();

     if ($this->RequestHandler->isPut())
            {
            $this->data=array(null);
            $this->autoRender = false;
            $acc_id = $this->activeUser['User']['acc_id'];

            $this->data['Role']['acc_id'] = $acc_id;

            unset($this->Role->RoleLanguage->validate['rle_id']);
             print_r($this->data);die();
            $this->Role->saveAll($this->data);
            }
}

我正在另一个视图中序列化数据,我从中调用 qbove 视图代码

$.ajax({
                                                    type: 'Put',
                                                    url: $('#role').attr('action'),
                                                    data: $('#role').serialize()
4

1 回答 1

0

可能是数据未通过调用 saveAll 时发生的模型验证测试。您是否尝试打印 $this->Role->invalidFields() 以查看是否有任何内容?

于 2012-07-03T19:42:56.607 回答