tags:

views:

767

answers:

2

hi in my cakephp forms_controller var $uses=array('Form','Field'); i m using two models(Form,Field)

While using $this->set('retrived',$this->Field->find("all",array('conditions'=>array('Field.formname'=>$formname,)))); in the forms_controller and in the view

           <?php endforeach; ?>

i m not getting the answer for it

Actually my table fields wil be like fieldname
formname type value a columns

In my 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);


                     }

The above method is where i m inserting the formname in my forms table And inserting tat formname with their fieldsname in the fields table

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

In the above formupdate method i m inserting the values of the corresponding values of that fields in the fields table...All the values are inserted correctly But in my formupdate.ctp view


Nothing s displayed in my view...eventhough the content is there in the table.. Please resolve my problem

A: 

By the names of your models, I think it's safe to conclude that you're trying to ouput some HTML. Since the question isn't really complete (where is the code?), we can't tell what's wrong with it.

A wild guess would be that something is being stripped there or ignored by your browser.

dr Hannibal Lecter
A: 

Aruna,

Please post the code you're using! It's possible that the error is something small, but without knowing what you're doing, it's impossible to help more than dr. Lecter did.

When you say that the fields table is updated correctly, do you mean that you can safely invoke the Model::save() method? Are you then calling Model::read() or Model::find() in the controller, then using the returned values from that to set a variable that can be accessed in the view?

Travis Leleu