我有一个重定向应该可以在我的应用程序$this->redirect('/Admin/Dashboard/Videos/Delete');
中删除视频时起作用,但是蛋糕正试图将我带到一个名为admin
的控制器,说管理控制器不存在,我的闪光信息也不会闪现,因为它应该。我有一个类似的rredirect,this->redirect('/Admin/Dashboard/Videos/Upload');
,它工作得很好但是这个并不是,我也尝试使用/Admin/Dashboard/Videos/Delete/:page'
,但它也没有用。如何正常工作?
我正在使用Cake2.4.4。
路线
Router::connect('/Admin/Dashboard/Videos/Upload', array('controller' => 'galleries', 'action' => 'uploadVideos'));
Router::connect('/Admin/Dashboard/Videos/Delete/:page', array('controller' => 'galleries', 'action' => 'deleteVideos'),array('page' => '[0-9]+'));
控制器
public function deleteVideos($id){
$this->set('title_for_layout', 'Apagar videos');
$this->layout = 'admin';
$this->loadModel('GalleryVideo');
$this->GalleryVideo->id=$id;
$this->Paginator->settings = $this->paginate;
$gallery_videos=$this->Paginator->paginate('GalleryVideo');
$this->set('gallery_videos', $gallery_videos);
if($this->request->is('post')){
if(!$this->GalleryVideo->exists()){
throw new NotFoundException('Erro, este video não foi encontrado.', 'default', array('class'=>'alert flashMessageDanger alert-dismissable'));
}
$options = array('conditions' => array('GalleryVideo.'.$this->GalleryVideo->primaryKey=>$id));
$gallery_video_delete = $this->GalleryVideo->find('first', $options);
if($this->GalleryVideo->delete()){
$this->Session->setFlash('O Video foi excluído com sucesso.', 'default', array('class'=>'alert flashMessageSuccess alert-dismissable'));
$this->redirect('/Admin/Dashboard/Videos/Delete');
}else{
$this->Session->setFlash('Erro, este Video não pôde ser apagado.', 'default', array('class' => 'alert flashMessageDanger alert-dismissable'));
}
}
}
查看
<h2>Videos <small>Apagar Videos</small></h2>
<?php echo $this->Session->flash();?>
<br>
<table class="table table-striped table-condensed table-hover">
<tr>
<?php
$i=0;
foreach( $gallery_videos as $gallery_video ):?>
<?php
echo "<td>";
echo $gallery_video['GalleryVideo']['iframe'];
echo "</td>";
echo "<td>";
echo $this->Form->postLink('Apagar', array('controller'=>'Galleries', 'action'=>'deleteVideos', $gallery_video['GalleryVideo']['id']), array('class'=>'btn btn-lg btn-danger large', 'title'=>'Apagar Video'), __('Tem a certeza que quer apagar este Video?'));
echo "</td>";
$i++;
if($i==1){
echo "</tr><tr>";
$i=0;
}
?>
<?php endforeach ?>
</tr>
</table>
答案 0 :(得分:0)
<强>路由器:强>
Router::connect('/Admin/Dashboard/Videos/Delete/:page', array('controller' => 'galleries', 'action' => 'deleteVideos'),array('page' => '[0-9]+'))
Router::connect('/Admin/Dashboard/Videos/Delete', array('controller' => 'galleries', 'action' => 'deleteVideos'))
<强>控制器:强>
public function deleteVideos($id = null){
....
$this->redirect(array('admin' => true, controller' => 'galleries', 'action' => deleteVideos'));