来自CakePHP中未发生的提交编辑 [英] From submission not happening in CakePHP edit

查看:110
本文介绍了来自CakePHP中未发生的提交编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编辑记录,但我的表单未提交,单击提交按钮后出现以下错误。如何解决此问题

I am trying to edit a record, but my form is not submitting,after clicking submit button i am getting the following error.How can i solve this

错误:在此服务器上找不到请求的地址'/ groups / edit / 12'。

Error: The requested address '/groups/edit/12' was not found on this server.

以下是我的代码

edit.ctp

<?php echo $this->form->create('Listing',array('url'=>array('controller'=>'groups',     'action'=>'edit'),'type' => 'post','enctype' => 'multipart/form-   data','id'=>'editform'));?>

<?php echo $this->form->input('Id',array('id'=>'Id','type'=>'hidden'));
echo $this->form->input('Slug_Category',array('id'=>'SlugCat','type'=>'hidden'));
echo $this->form->input('SlugGroup',array('id'=>'SlugGroup','type'=>'hidden','value'=>$listingdata['Group']['group_slug']));
echo $this->form->input('Slug_SubCategory',array('id'=>'SlugSubcattxt','type'=>'hidden'));

   echo $this->form->hidden('Status',array('value'=>'A'));
echo $this->form->hidden('User_Id', array('value'=> $current_user['id']));
echo $this->form->hidden('Cr_Uid', array('value'=> $current_user['id']));
echo $this->form->hidden('Upd_Uid', array('value'=> $current_user['id']));

    echo('<div class="formrow">');
    echo $this->form->label('Title', '*Title',
    array(
        'class' => 'formlabel'
    ));
   echo $this->form->input('Name', array(
    'class' => 'formtextbox required',
            'id' => 'Name',
    'label' => false,
    'div' => false,
    'maxlength' => 200,
    'tabindex' => 1,
    'autocomplete' => 'off',
    'style'=>'padding-left:12px'
    ));
   echo('</div>');
echo('<div class="formrow">');
echo $this->form->label('Price', 'Price',
        array(
                'class' => 'formlabel'
        ));
echo('<div class="formrowcurrencydiv">');
echo $this->form->input('price', array(
        'class' => 'formtextbox',
        'id' => 'Price',
        'label' => false,
        'div' => false,
        'tabindex' => 8,
        'autocomplete' => 'off',
        'style'=>'margin-left:2px;'
));
echo('<div class="formrowcurrency" id="formrowcurrency">');
echo('</div>');
echo('</div>');
echo('</div>');



echo('<div class="formrow">');
echo $this->form->label('contact_no', 'Contact no',
        array(
                'class' => 'formlabel'
        ));
echo $this->form->input('contact_no', array(
        'class' => 'formtextbox',
        'id' => 'contact_no',
        'label' => false,
        'div' => false,

        'tabindex' => 9,
        'autocomplete' => 'off',
        'style'=>'padding-left:12px'
));
echo('</div>');


echo('<div class="formrow">');
echo $this->form->label('Description','Description',array('class'=>'formlabel'));
echo $this->form->textarea('Description', array('rows'=>'15','cols'=>'70','class'=>'description','tabindex' => 10));
echo('</div>');?>
<?php                           
    echo $this->form->submit('Submit', array(
    'class' => 'button',
    'div' => false,
    'tabindex' => 11,
    'id'=>'submitbtn'
    ));
?>
<?php echo $this->form->end();?>

控制器:

function edit($sluggroup=null , $listingslug=null){


    $listingdata=$this->Listing->findBySlugListing($listingslug);
    $listid=$listingdata['Listing']['Id'];
    $this->set('listingdata',$listingdata);

    if ($this->request->is('post')) {
        $this->Listing->Id = $this->request->data['Listing']['Id'];

        $this->request->data['Listing']['Slug_Group'] = $listingdata['Group']['group_slug'];
        $this->request->data['Listing']['Group_Privacy']=$listingdata['Group']['privacy'];
        $this->request->data['Listing']['Group_Id']=$listingdata['Group']['id'];





        if($this->Listing->save($this->data)) {

            $this->redirect('http://'.$_SERVER['SERVER_NAME'].'/'.$sluggroup.'/'.$listingslug.'/listing');
        }
    }
    else
    {
        $this->data = $this->Listing->findById($listid);
    }

}

我有以下两条路线route.php

i have the following two routes in routes.php

Router::connect('/groups/edit', array('controller' => 'groups', 'action' => 'edit'));
Router::connect('/:sluggroup/:listingslug/:action', array('controller' => 'groups', 'action' => 'editlisting'),array(
    'pass' => array('sluggroup','listingslug')));


推荐答案

我不确定我能完全理解你在做什么要做,但路由:

I am not entirely sure I understand what you are trying to do, but the route:

Router::connect('/:sluggroup/:listingslug/:action',
    array('controller' => 'groups', 'action' => 'editlisting'),
    array('pass' => array('sluggroup','listingslug'))
);

似乎会触发,它将以以下方式处理请求:

is the one that seems to fire and it will process the request as:

/ groups / editlistings /

/groups/editlistings/

由于您的控制器似乎没有这种方法,因此会显示错误。

Since your controller does not seems to have such method, you get the error shown.

尝试将其更改为:

Router::connect('/:sluggroup/:listingslug/:action',
    array('controller' => 'groups', 'action' => 'edit'),
    array('pass' => array('sluggroup','listingslug'))
);

这篇关于来自CakePHP中未发生的提交编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆