2009-04-10 66 views
-1

在我的CakePHP forms_controller我:CakePHP的兩款車型

var $uses=array('Form','Field'); 
// ... 
$this->set('retrived',$this->Field->find("all",array('conditions'=>array('Field.formname'=>$formname,)))); 

,並在視圖:

<?php foreach ($retrived as $r): ?> 
    <?php echo $r['Field']['fieldname']; ?><br> 
<?php endforeach; ?> 

我沒有得到它

其實我的表字段的答案將如:

fieldname 
    formname 
    type 
    value  

從我forms_controller更多細節:

function views() 
{ 
    if (!empty($this->params['form'])) 
    { 
     $this->set('fieldctr',$this->params['form']['formfieldctr']); 
      $fieldctr=$this->params['form']['formfieldctr']; 

     if(!empty($this->params['form']['formnameelements'])) 
     { 
      $this->set('formname',$this->params['form']['formnameelements']);//formname 
      $this->Form->saveField('name',$this->params['form']['formnameelements']); 
     } 
     else 
     { 
      $this->set('formname','MyForm');//formname 
      $this->Form->saveField('name','MyForm'); 
     } 

     $this->Form->saveField('body',$this->params['form']['formelements']);//inserts into database 

     $ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1"); 
     $newid=$ret[0]['forms']['id'];echo $newid; 
     $upd=$this->Form->query("update forms set ctr=$fieldctr where id= $newid"); 
     $formname=$this->params['form']['formnameelements']; 

     $n="$formname"; 

     $array = $this->params['form']['formfieldnameelements']; 
     $comma_separated = explode(",", $array); 
     for($i=0;$i<$fieldctr;$i++) 
     { 
      echo $comma_separated[$i]; 
      echo "  "; 
      $n="$comma_separated[$i]"; 

      //insert the fields of each form to the table fields 
      $this->data['Field']['fieldname'] = $comma_separated[$i]; 
      $this->data['Field']['formname'] = $formname; 

      $this->Field->saveAll($this->data); 
     } 

,上面的方法在那裏我將在我的形式表表格名稱。

和插入該表格名稱與其在領域表fieldsname:

function formupdate() 
{ 
    $this->set('fieldctr',$this->params['form']['formfieldctr']); 
    $fieldctr=$this->params['form']['formfieldctr']; 

    $this->set('formname',$this->params['form']['formnameelements']);//formname 
    $formname=$this->params['form']['formnameelements']; 

    $ret = $this->Field->query("SELECT fieldname FROM fields WHERE fields.formname = "."'$formname'"."order by id ASC"); 
    for($q=0;$q<$fieldctr;$q++) 
    { 
     $fieldname[$q]=$ret[$q]['fields']['fieldname']; 
    } 

    $this->set('retrived',$this->Field->find("all",array('conditions'=>array('Field.formname'=>$formname)))); 

    $array = $this->params['form']['formfieldvalueelements']; 
    $comma_separated = explode(",", $array); 

    for($i=0;$i<$fieldctr;$i++) 
    { 
     echo $comma_separated[$i]; 
     echo "  "; 
     $n="$comma_separated[$i]"; 

     echo $fieldname[$i]; 

     $this->Field->updateAll(array('Field.value' => "'$comma_separated[$i]'"),array('Field.fieldname' => $fieldname[$i],'Field.formname'=>$formname)); 
     } 
    $this->set('retrived',$this->Field->find("all",array('conditions'=>array('Field.formname'=>$formname,)))); 

} // end of function formupdate 

在上面formupdate方法我插入的對應的值的值的字段表中的字段...所有的值插入正確的 - 但在我formupdate.ctp觀點:


沒有顯示在我看來... eventhough內容爲t在這裏表..

請解決我的問題

+0

您的代碼*看起來*確定。你能發佈更多信息嗎?你有錯誤嗎?或者只是沒有顯示?你能發佈更多的視圖代碼嗎? – 2009-04-10 14:05:12

回答

0

通過你的模型的名稱,我認爲它是安全的結論是你想輸出中的一些HTML。由於問題並不完全(代碼在哪裏?),所以我們不能說出它有什麼問題。

一個瘋狂的猜測是某些東西被剝離或被瀏覽器忽略。

0

Aruna,

請發表您正在使用的代碼!錯誤可能很小,但不知道你在做什麼,不可能比dr博士更有幫助。萊克做到了。

當你說fields表被正確更新時,你的意思是說你可以安全地調用Model :: save()方法嗎?然後,你是否在控制器中調用Model :: read()或Model :: find(),然後使用返回的值設置可以在視圖中訪問的變量?