cakephp $ this-> request-is("post")只返回一个表单的false,真奇怪吗?

Hao*_*Hao 4 cakephp

我在网站上有很多表格.它们都是以类似的方式创建的

<?php echo $this->Form->create('SysUser');?>
<fieldset>
<legend><?php echo __('Edit Basic Information'); ?></legend>
<?php
echo $this->Form->input('SysUser.first_name');
echo $this->Form->input('SysUser.family_name',array('label'=>__("Last Name")));
echo $this->Form->input('SysUser.mobile_phone_number');
echo $this->Form->input('SysUser.user_name',array('label'=>__("Screen Name")));
echo $this->Form->input('action', array('type'=>'hidden','value'=>'edit_basic_info'));
echo $this->Form->input('SysUser.id', array('type'=>'hidden','value'=>$user["id"]));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
Run Code Online (Sandbox Code Playgroud)

但是一种形式的类型变成"放",而不是"后".当我创建这些表单时,我从未明确地将类型设置为"post".我收集CakePHP设置发布的默认值.现在,我创建这种新特殊形式的方式似乎有些不对劲.奇怪的是,这是几天前工作的!

我不知道出了什么问题.就这个:

<?php echo $this->Form->create('Member'); ?>
<fieldset>
    <legend><?php echo __('Basic Profile Setup'); ?></legend>
    <?php
    echo $this->Form->input('Member.gender_id');
    $w = array();
    for ($i = 40; $i < 120; $i++) {
        $w[$i] = $i . " kg";
    }
    $h = array();
    for ($i = 120; $i < 230; $i++) {
        $h[$i] = $i . " cm";
    }
    echo $this->Form->input('Member.height', array(
        'options' => $h,
        'empty' => __("choose one")
    ));
    echo $this->Form->input('Member.weight', array(
        'options' => $w,
        'empty' => __("choose one")
    ));
    $options['minYear'] = date('Y') - 78;
    $options['maxYear'] = date('Y') - 18;
    echo $this->Form->input('Member.birthdate', $options);
    echo $this->Form->input('Member.residential_location_id', array('label' => __("City/Location")));
    echo $this->Form->input('Member.occupation_id',array('id'=>'MemberOccupationId'));
    echo $this->Form->input('action', array('type' => 'hidden', 'value' => 'create_member'));
    ?>
</fieldset>
<?php
echo $this->Form->end(array("label" => __('Save')));
Run Code Online (Sandbox Code Playgroud)

shx*_*fee 17

Request data含有Model.id CakeRequest::method()设为put.在cakephp中处理此问题的首选方法如下.

if ($this->request->is(array('post', 'put'))) {
    // Code
}
Run Code Online (Sandbox Code Playgroud)

你可以在烘焙控制器中看到这个,编辑动作.


小智 5

不确定为什么会这样,但你可以这样设置表单类型:

<?php echo $this->Form->create('Member', array('type' => 'post')); ?>
Run Code Online (Sandbox Code Playgroud)