Cakephp 使用一个模型读取数据,使用另一个模型保存数据
我有一个名为google_news.php的模型,它使用外部数据,另一个名为saved_news.php的模型使用我在数据库中保存的_news表 在我的控制器中,我声明我使用这两种型号:Cakephp 使用一个模型读取数据,使用另一个模型保存数据,cakephp,save,Cakephp,Save,我有一个名为google_news.php的模型,它使用外部数据,另一个名为saved_news.php的模型使用我在数据库中保存的_news表 在我的控制器中,我声明我使用这两种型号: var $uses = array('GoogleNews', 'SavedNews'); 我的索引函数读取数据: $this->set('news',$this->GoogleNews->find('all')); 我的观点是这样的: <?php foreach( $news as
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; ?>
如何在我的控制器中编写add函数以将每个数据保存到我的数据库?您应该将需要保存的内容分配到$this->data['ModelName']中作为字段数组。看一看书中的内容。这将进一步解释需要遵循的格式。您的问题似乎令人困惑。你看过博客教程了吗?