2012-10-01 58 views
-1

您好我有一个cakephp页面,当您将鼠标悬停在链接上时,它会显示正确的链接,但是当您单击该链接时,它会将您带到完全不同的/错误的页面。CakePhP链接

我认为它与我的观点错误,所以我会在这里包括该网站的相关部分,所发生的事情是add link正在用户fields/viewfields/add_new

 <tr> 
       <td align='center'><?php echo $templates['Template']['name'] ;?></td> 
      <td align='center'><?php echo $templates['Template']['description']; ?> </td> 
       <td align='center'> 
        <?php echo $this->Form->Html->link('Add', array('controller' => 'Fields','action'=>'add_new',$templates['Template']['id'])); ;?> | 
        <?php echo $this->Form->Html->link('View', array('controller' => 'Fields','action'=>'view',$templates['Template']['id'])); ;?> | 
        <?php echo $this->Form->Html->link('Edit', array('controller' => 'Templates','action'=>'edit',$templates['Template']['id'])); ;?> | 
        <?php echo $this->Form->Html->link('Delete', array('controller' => 'Templates','action'=>'delete',$templates['Template']['id'])); ;?></td> 
     <tr> 





function add_new($id=null){ 
     //allows users to add another field to an existing template 
     $this->set('title_for_layout', 'Create Fields'); 
     $this->set('stylesheet_used', 'homestyle'); 
     $this->set('image_used', 'eBOXLogoHome.png'); 
     $this->layout='home_layout'; 


     if(($this->Field->save($this->request->data))) 
     { 

     $id = $this->data['Field']['template_id']; 

     $this->set('id',$id); 
     $this->redirect(array('controller'=>'Fields', 'action'=>'view',$id)); 

     } 
      $this->set('id',$id); 
     } 
+0

:在此处分享您的控制器代码 – chetanspeed511987

+0

我已经意识到它会自动重定向该页面。我现在更新控制器代码 – user1393064

回答

0
function add_new($id=null){ 
     //allows users to add another field to an existing template 
     $this->set('title_for_layout', 'Create Fields'); 
     $this->set('stylesheet_used', 'homestyle'); 
     $this->set('image_used', 'eBOXLogoHome.png'); 
     $this->layout='home_layout'; 


     //this sets the parameter as a variable 
     $this->set('id', $id); 
     //if the data posts to the databse 
     if($this->request->is('post')) 
     { 
      //creates an instance of field in the database 
      $this->Field->create(); 
      //if the field saves to the database 
      if ($this->Field->save($this->request->data)) 
      { //if the user clicks this button 
       $id = $this->data['Field']['template_id']; 

       $this->set('id',$id); 
       $this->redirect(array('controller'=>'Fields', 'action'=>'view',$id)); 


      } 

     } 

    } 
0

link功能部分HtmlHelper类。所以,你需要从你的函数调用删除->Form到:

<?php echo $this->Html->link('Add', array('controller' => 'fields', 'action'=>'add_new',$templates['Template']['id'])); ;?> 

此外,蛋糕公约呼吁控制器名称是小写,所以指定控制器:

('controller' => 'fields',

,而不是

('controller' => 'Fields',

+0

没有骰子,仍然去查看不add_new – user1393064

+0

也许还尝试摆脱PHP标签中的额外的分号。也就是说,尝试从';?>'中删除分号。 –

+0

没有那个运气 – user1393064