使用一种模型读取数据,使用另一种模型保存数据
我有一个名为 google_news.php
的模型,它使用外部数据,另一个模型 saved_news.php
使用数据库中的 saving_news 表,
在我的控制器中,我声明我使用这两个模型:
var $uses = array('GoogleNews', 'SavedNews');
我的索引函数读取数据:
$this->set('news',$this->GoogleNews->find('all'));
我的视图如下所示:
<?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; ?>
如何在我的控制器中编写添加函数以将每个数据保存到我的数据库中?
I have 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将需要保存到 $this->data['ModelName'] 中的内容指定为字段数组。看看书中的保存数据。这将详细解释需要遵循的格式。
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.