【问题标题】:Using one model to read and another to save data使用一种模式读取数据,另一种模式保存数据
【发布时间】:2010-12-06 11:00:35
【问题描述】:

我有一个名为 google_news.php 的模型使用外部数据,另一个模型 saved_news.php 使用我在数据库中的 saved_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; ?>

如何在我的控制器中编写添加函数来将每个数据保存到我的数据库中?

【问题讨论】:

  • 您的问题似乎令人困惑。您浏览过博客教程了吗?

标签: cakephp save


【解决方案1】:

您应该将需要保存的内容分配到 $this->data['ModelName'] 作为字段数组。看看书中的saving data。这将解释更多关于需要遵循的格式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 2018-07-05
    相关资源
    最近更新 更多