首页 \ 问答 \ CakePHP删除Cookie问题(CakePHP Delete Cookie Issue)

CakePHP删除Cookie问题(CakePHP Delete Cookie Issue)

我浏览过类似的其他人的问题,但似乎没有任何东西像我正在经历的那样。 如果之前已经解决了这个问题,请随时引用我的另一篇文章。

当用户验证在本地存储一些基本用户信息时,我写了一个cookie。 当用户注销时,我试图删除cookie变量,但不会删除。 如果我使用destroy方法,那么cookie就会被移除,但我很好奇我在这里做错了什么:

Cookie是这样写的并且正在工作:

function login(){
    if($this->Auth->login($this->data)){
        $this->Cookie->write('User.email',$this->data['User']['email'],true, '1 day');
    }
}

但是,使用删除功能不起作用......

function logout(){
    $this->Cookie->delete('User');
    if($this->Auth->logout($this->data)){
        //auto redirected
    }
}

如果我用destroy替换delete,它就可以了。 这是不行的,因为cookie数据是加密的? 我可能会做一些愚蠢的事,但我似乎无法弄明白。

我正在使用这个cookie来坚持通过会话。 我只希望在用户点击退出按钮时将其删除。

谢谢!


I've browsed through other people's issues similar to this, but nothing seems to be exactly like what I am experiencing. Please feel free to reference me to another article if this has been addressed before.

I have written a cookie when a user authenticates that stores some basic user info locally. When the user logs out, I am trying to delete the cookie variable, but is does not delete. If I use the destroy method, then the cookie is removed, but I am curious as to what I am doing wrong here:

Cookie is written like this and is working:

function login(){
    if($this->Auth->login($this->data)){
        $this->Cookie->write('User.email',$this->data['User']['email'],true, '1 day');
    }
}

However, using the delete function does not work...

function logout(){
    $this->Cookie->delete('User');
    if($this->Auth->logout($this->data)){
        //auto redirected
    }
}

If I replace delete with destroy, it works. Is this not working because the cookie data is encrypted? I'm probably doign something stupid, but I can't seem to figure it out.

I'm using this cookie to persist through sessions. I only want it deleted if the user clicks a logout button.

Thanks!


原文:https://stackoverflow.com/questions/5655255
更新时间:2023-08-22 17:08

最满意答案

首先,主题的创建可以简化如下:

const subject = rx.Observable.fromEvent(blah, 'event')
              .filter(blah)
              .map(blah)
              .share();

share方法将从流中创建Subject。 如果您将此主题实例返回给每个订阅者,您将获得相同的行为并且看起来更好。

 a) if the events come in super fast is the handler going to process
 them synchronously and in the right order given the way I have it?

事件将以正确的顺序逐个推送到整个链中。 这意味着,在处理下一个值之前,通过'fromEvent'进入的事件将被推送到整个链中,直到您订阅它为止(除非在它们之间存在异步运算符:))。 Ben Lesh在角度连接2015解释了这一点: https//www.youtube.com/watch?v = KOOT7BArVHQ (你可以观看整个演讲,但是在17分左右,他将数组与可观察数据进行比较)。

b) if the different handlers handle the event at different speeds are 
they all going to wait till the slowest handler is through before the    
next event is provided? or will they all sort of buffer and handle at  
they're own pace?

他们将按照自己的节奏处理事件。 请检查以下示例:

let interval$ = Rx.Observable.interval(1000).share();

interval$.concatMap((val) => {
    console.log('called');
    return Rx.Observable.of(val).delay(3000)
  })
  .subscribe((val) => console.log("slow ", val));

interval$.subscribe((val) => console.log("fast ", val));

在这里,我使用一个可以观察到的区间,我将其转换为一个主题。 所以它会每秒发出一个事件。 我有一个正在获取值的订阅,处理此值(需要2秒)然后采用下一个(使用concatMap)。 另一个订阅会立即处理它们。 如果您运行此代码(jsbin here: https ://jsbin.com/zekalab/edit?js,console),您将看到他们都按照自己的节奏处理事件。

因此,他们不会等待最慢的处理程序,它将在内部缓冲。

如果最慢的处理器比抛出事件的频率慢,那么您描述的情况可能会有一些危险的情况。 在这种情况下,您的缓冲区将继续增长,最终您的应用程序将崩溃。 这是一个称为背压的概念。 您获得的事件比处理事件的速度快。 在这种情况下,您需要在最慢的处理器上使用“缓冲”或“窗口”等运算符来避免这种情况。


First of all, the creation of the subject can be simplified like this:

const subject = rx.Observable.fromEvent(blah, 'event')
              .filter(blah)
              .map(blah)
              .share();

The share method will create a Subject from the stream. If you return this subject instance to every subscriber, you'll get the same behaviour and it looks better.

 a) if the events come in super fast is the handler going to process
 them synchronously and in the right order given the way I have it?

Events are going to be pushed through the entire chain one by one and in the correct order. Meaning, an event that comes in through the 'fromEvent' will be pushed through the entire chain until the point you are subscribed to it, before handling the next value (unless there's an async operator in between :)). Ben Lesh explained this at angular connect 2015: https://www.youtube.com/watch?v=KOOT7BArVHQ (you can watch the whole talk but it's around min 17 where he compares arrays to observables).

b) if the different handlers handle the event at different speeds are 
they all going to wait till the slowest handler is through before the    
next event is provided? or will they all sort of buffer and handle at  
they're own pace?

They will handle the events at their own pace. Check the following example:

let interval$ = Rx.Observable.interval(1000).share();

interval$.concatMap((val) => {
    console.log('called');
    return Rx.Observable.of(val).delay(3000)
  })
  .subscribe((val) => console.log("slow ", val));

interval$.subscribe((val) => console.log("fast ", val));

Here I use an interval observable that I convert into a subject. So it will send out an event every second. I have one subscription that is taking a value, handling this value (which takes 2seconds) and then taking the next one (with the concatMap). And another subscription that processes them immediately. If you run this code (jsbin here: https://jsbin.com/zekalab/edit?js,console), you'll see that they both handle the events at their own pace.

So they do not wait for the slowest handler and it will be buffered internally.

The situation you are describing could have potentially some dangerous situation if the slowest processor is slower than the frequency the events are thrown. In that case, your buffer would keep growing and eventually your application would crash. This is a concept called back pressure. You are getting events faster than you are processing them. In that case, you need to use operators like 'buffer' or 'window' on the slowest processors to avoid this situation.

相关问答

更多
  • 我可能会使用fromArray + flatMap代替: var urls = ["https://api.github.com/users/manju4ever","https://api.github.com/users"]; var responses = Rx.Observable.fromArray(urls) //Implicitly handle the promises .flatMap(function(url) { ...
  • 您可以尝试为每个调用添加一个catch并返回一个带有错误消息的新observable,如果一个请求失败,则应该停止forkJoin失败。 然后,您可以过滤掉故障,或添加逻辑以在最终的.map中处理它们。 例如。 const fetchPhotosEpic = action$ => action$.ofType(LOCATIONS_RECEIVED) .map(action => action.payload) .mergeMap((data) => { let pro ...
  • 你基本上正在创建你自己的Subject的实现。 尝试这个: import { Observable } from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject'; export class MyService { private source = new Subject(); data$ = this.source.asObservable(); constructor() {} next(data ...
  • 您会立即看到错误,因为您传递的第一个observable会同步发出其值。 (其他可观察量也同步发出它们的值,但在这种情况下这无关紧要。) zip按照传递的顺序逐个订阅传递的observable。 在订阅第一个observable时, zip同步接收所有可观察的值和连接的错误。 然后它会发出自己的错误并完成。 如果指定可选的scheduler参数 - 以便observables异步发出它们的值 - 您将看到您期望的行为: var age$ = Rx.Observable.concat( Rx.Obser ...
  • 这应该够了吧: var array = ['http://localhost:4444/text/88', 'http://localhost:4444/other/77']; var source = Rx.Observable.fromArray(array).concatMap(httpGet); function httpGet(url) { return axios.get(url); } var subscription = source.subscribe( functio ...
  • 您有两个或三个错误的组合。 首先, combineLatest()中的lambda不对新闻id数组进行操作,而是对包含该数组的单个项目进行操作。 因此flatmap()是不必要的, concatMap() 。 其次,您不需要从fetch()创建Observable ,如 第三,你所拥有的combineLatest()不会在加载新闻时提供combineLatest()的Promise,而是在加载availableNews和pager时。 因此,您必须使用combineLatest()创建第三个Observab ...
  • 看文件 。 看起来您需要使用像require.js这样的AMD加载器来在客户端运行此代码。 例如: test