我正在尝试编辑记录,但是我的表单没有提交,点击提交按钮后我收到以下错误。我怎么能解决这个问题
错误:在此服务器上找不到请求的地址'/ groups / edit / 12'。
以下是我的代码
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);
}
}
我在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')));
答案 0 :(得分:0)
我不完全确定我明白你要做什么,但路线:
Router::connect('/:sluggroup/:listingslug/:action',
array('controller' => 'groups', 'action' => 'editlisting'),
array('pass' => array('sluggroup','listingslug'))
);
似乎是一个,它将处理请求:
/组/ editlistings /
由于你的控制器似乎没有这样的方法,你会收到错误。
尝试将其更改为:
Router::connect('/:sluggroup/:listingslug/:action',
array('controller' => 'groups', 'action' => 'edit'),
array('pass' => array('sluggroup','listingslug'))
);