开发者

Using one model to read and another to save data

开发者 https://www.devze.com 2023-01-29 15:07 出处:网络
I h开发者_运维百科ave a model named google_news.php which uses the external data, and another model saved_news.php which uses my saved_news table in database,

I h开发者_运维百科ave a model named google_news.php which uses the external data, and another model saved_news.php which uses my saved_news table in database,

In my controller I declared that Im using this two models:

var $uses = array('GoogleNews', 'SavedNews');

and my index function reads data:

$this->set('news',$this->GoogleNews->find('all'));

and my view looks like this:

<?php foreach( $news as $newsItem ) : ?>

<?php echo $html->link($newsItem['GoogleNews']['title'], array('action'=>'add',    $newsItem['GoogleNews']['title'])); ?>

<?php echo $newsItem['GoogleNews']['encoded']; ?>

<em>
<hr>

<?php endforeach; ?>

How to write the add function in my controller to save each data to my database?


You should assign what you need to be saved into $this->data['ModelName'] as array of fields. Take a look at saving data in the book. That will explain more about the formatting that needs to be followed.

0

精彩评论

暂无评论...
验证码 换一张
取 消