A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearCakephp using two models - page 1
User InfoPosts
Cakephp using two models#1
In my CakePHP forms_controller I have:

var $uses=array((Form(,(Field();
// ...

and in the view:

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

I(m not getting the answer for it

Actually my table fields wil be like:


More details from my forms_controller:

function views()
if (!empty($this->params[(form(]))


$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");


$array = $this->params[(form(][(formfieldnameelements(];
$comma_separated = explode(",", $array);
echo $comma_separated[$i];
echo " ";

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


The above method is where I(m inserting the formname in my forms table.

And inserting that formname with their fieldsname in the fields table:

function formupdate()


$ret = $this->Field->query("SELECT fieldname FROM fields WHERE fields.formname = "."($formname("."order by id ASC");


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

echo $comma_separated[$i];
echo " ";

echo $fieldname[$i];

$this->Field->updateAll(array((Field.value( => "($comma_separated[$i]("),array((Field.fieldname( => $fieldname[$i],(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 is displayed in my view... eventhough the content is there in the table..

Please resolve my problem

posted date: 2009-04-10 02:46:00

Re: Cakephp using two models#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-10 02:46:01

Re: Cakephp using two models#3
Your code looks OK. Could you post more info? Are you getting an error? Or just nothing displays? Could you post more of your view code?

posted date: 2009-04-10 06:05:00

Re: Cakephp using two models#4
Yes, please post code and re-edit your post. I'm not sure what you're asking here.

posted date: 2009-04-11 12:55:00

Re: Cakephp using two models#5
The values are present in the table fields but it is not displaying inthe view...

posted date: 2009-04-12 22:51:00

Re: Cakephp using two models#6
The fields table is updated correctly vit the data but it s not displaying the data in the VIEw

posted date: 2009-04-12 22:52:00

Re: Cakephp using two models#7
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.

posted date: 2009-04-13 07:23:00

Re: Cakephp using two models#8
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?

posted date: 2009-04-13 08:34:00

Re: Cakephp using two models#9
Doesn't seem as though your asking a question more of a "fix it for me." Could focus this down to a simple point?

posted date: 2009-04-27 16:47:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.