2012-10-01 4 views
-1

안녕하세요. cakephp 페이지가 있습니다. 링크를 가리키면 올바른 링크가 표시되지만 링크를 클릭하면 완전히 다른/잘못된 페이지로 연결됩니다.CakePhP Linking

나는 그것의 내보기에 오류 가정, 그래서 무슨 일이 일어나고 있는지 여기 사이트의 관련 부분을 포함 할 것이다는 add linklink 기능 fields/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

하지 fields/view에 사용자를 복용입니다 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