Kohana模型节省了两次

Kohana模型节省了两次

本文介绍了Kohana模型节省了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了Kohana 3.2的新副本,构建了数据库,编写了第一个模型,然后尝试对其进行测试.除了模型的"save"方法执行两次之外,一切工作正常,最后我在数据库中添加了两个新条目,而不是一个.仅当我使用下面显示的查找"代码时,才会出现此问题.

I just installed a fresh copy of Kohana 3.2, built my database, wrote my first model, and tried testing it. Everything works fine except the model's "save" method is being executed twice--I end up with two new entries in the database instead of one. The problem only occurs when I use the "find" code shown below.

为什么模型的保存将执行两次,一次按预期执行,一次由于查找而执行?

Why would the model's save get executed twice, once as expected and once because of the find?

代码如下:

class Controller_Welcome extends Controller {

public function action_index()
{

    $rating = ORM::factory('rating');

    $rating->user_id = 1;
    $rating->userlevel_id = 3;
    $rating->category_id = 1;
    $rating->page_id = 1;
    $rating->rating = 4;
    $rating->comments = 'This one is a real killer';
    $rating->ratingstatus_id = 1;

    $rating->save();

    $found = ORM::factory('rating')
        ->where('id', '=', 1)
        ->find();

    $this->response->body($found->comments); // Test to check for found data
}

} // End Welcome

提前谢谢!

推荐答案

有两个问题导致了我的问题:

There are two issues that were causing my problem:

  1. 我的服务器上没有favicon.ico.许多浏览器请求一个,所有不是实际文件或目录的URL都被重定向到索引页面.每次我加载页面时,浏览器都会请求一个缺少的图标,并重定向到我的索引页面-两个请求.在查看了我的日志后,该页面向我提示: http://forum.kohanaframework.org/discussion/7447/error-kohana_request_exception/p1

添加图标图标后,偶尔仍然会看到重复请求行为.事实证明,这是Google Chrome的一种行为-Chrome会预取页面,因此每次更改内容时,Chrome都会预取并缓存该页面(添加请求).

After I added a favicon, I still saw the double request behavior occasionally. It turns out it was a behavior of Google Chrome--Chrome prefetches pages, so each time I changed the content, Chrome would prefetch and cache the page (adding a request).

添加图标后,使用除Chrome之外的浏览器,一切正常.

After adding a favicon and when using a browser besides Chrome, everything behaves as expected.

这篇关于Kohana模型节省了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:38