2012-09-25 4 views
1

저는이 문제를 파악하기 위해 많은 시간을 보냈으며, 행운이 없었습니다. 나는 아무런 성공도없이 라우팅을 시도했다. 먼저 로직을 입력하고 코드를 입력합니다.Cakephp 매개 변수가 전달되지 않습니다.

  1. 사용자/PRA/필드 /보기/1 fields.template_id = 1
  2. 사용자가 새로운 분야/프라/필드/add_new/1가하게된다 추가 클릭 필드 목록에서 찾고있다 그들이 작성하는 새로운 필드에 대해 에 원하는 정보를 입력하는 양식으로 이동합니다. 사용자가 추가를 클릭 할 때/제출
  3. , 새로운 필드는 사용자가 다시 촬영하는 데이터베이스
  4. 에 저장됩니다/프라/필드 /보기/1 그래서 그들은 새로운 필드 템플릿에 추가 볼 수 있습니다
  5. 이 로 다시 리디렉션에 올 때

현재 처음 3 단계는 일어나고, 그러나 사용자는 /pra/Fields/view/ 여기

로 리디렉션되고는 add_new 기능

코드입니다 여기
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'; 
    $name=$this->Field->field('template_id', array('template_id'=>$id)); 
    //if the field data saves 
    $this->set('name',$name); 
    if(($this->Field->save($this->data))) 
    { 
     //user is redirected to fields/view/$name 
     $this->redirect(array('controller'=>'Fields', 'action'=>'view',$name)); 
    } 
    //sets the $id variable 
    $this->set('id',$id); 

는 add_new보기

<table id="formatform"> 
     </br></br> 
     <?php 
      $options = array('Money'=>'Money','Text'=>'Text','Description'=>'Description'); 
      ?> 
     <?php echo $this->Form->create('Field', array('action'=>'add_new')); ?> 
     <?php echo $this->Form->input('id',array('type'=>'hidden')); ?> 
       <tr> 
       <td></td> 
       <td><?php echo $this->Form->input('template_id',array('type'=>'hidden','default' => $id)); ?></td> 
       </tr> 

       <tr> 
       <td align='center'>Field Name:</td> 
       <td align='left'><?php echo $this->Form->input('name', array('label'=>false)); ?></td> 
       </tr> 

       <tr> 
       <td align='center'>Default Value:</td> 
       <td align='left'><?php echo $this->Form->input('default_value', array('label'=>false)); ?></td> 
       </tr> 
       <tr> 
       <td align='center'>Field Type:</td> 
       <td align='left'><?php echo $this->Form->input('field_type', array('label'=>false,'type'=>'select','options'=>$options)); ?></td> 
       </tr> 

       <tr> 
       <td align='center'>Description:</td> 
       <td align='left'><?php echo $this->Form->input('description', array('label'=>false)); ?></td> 
       <td><?php echo $this->Form->input('active', array('type'=>'hidden','default'=>true)); ?></td> 
       </tr> 




    <td></td> <td align = "left"><?php echo $this->Form->end('Submit');?></td> 

이며, 여기

function view($name){ 
    //lists information about fields that correspond to the 
    //template they have clicked 'view' on 
    $this->set('title_for_layout', 'Field Details'); 
    $this->set('stylesheet_used', 'homestyle'); 
    $this->set('image_used', 'eBOXLogoHome.png'); 
    $this->layout='home_layout'; 
    //sets $conditions where template_id=$name and field.active=true 
    $conditions=array(
     "AND"=>array(
     'template_id'=> $name, 
     'Field.active'=>true)); 
    //finds all fields where 'conditions'=$conditions 
    $fields = $this->Template->Field->find('all',array( 
     'conditions' => $conditions)); 
    //sets all the variables  
    $this->set('conditions', $conditions); 
    $this->set('field', $fields); 
    $this->set('field', $this->paginate('Field', $conditions)); 


} 

답변

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'; 

확인하는 경우를 $ name은 (는) 비어 있지 않습니다.

$name = $this->Field->field('template_id', array('template_id'=>$id)); 
if(!empty($name)){ 
    $this->set('name',$name); 
    if(($this->Field->save($this->data))) 
    { 
     //user is redirected to fields/view/$name 
     $this->redirect(array('controller'=>'Fields', 'action'=>'view',$name)); 
    } 
} 

코드의 나머지

//sets the $id variable 
$this->set('id',$id); 
+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->set('id',$id); 

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

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

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

    } 
    } 
관련 문제