Welcome Guest, Not a member yet? Register   Sign In
Send new Cookie() to Response
#1

It is not clear from the documentation how to work with Cookies and CookieStore. Can you show a detailed example with explanations?

PHP Code:
        $cookie = new Cookie('test_1''12345',    [
            'expires'  => new DateTimeImmutable('+2 hours'),
        ]);
        $cookie2 = new Cookie('test_2''67890',    [
            'expires'  => new DateTimeImmutable('+5 hours'),
        ]);
        $store = new CookieStore([
            $cookie$cookie2,
        ]); 
Reply
#2

(This post was last modified: 08-03-2023, 04:43 AM by luckmoshy.)

PHP Code:
<?php

use CodeIgniter\Cookie\Cookie;
use 
DateTime;

// Using the constructor
$cookie = new Cookie(
    'remember_token',
    'f699c7fd18a8e082d0228932f3acd40e1ef5ef92efcedda32842a211d62f0aa6',
    [
        'expires'  => new DateTime('+2 hours'),
        'prefix'  => '__Secure-',
        'path'    => '/',
        'domain'  => '',
        'secure'  => true,
        'httponly' => true,
        'raw'      => false,
        'samesite' => Cookie::SAMESITE_LAX,
    ]
); 




https://codeigniter.com/user_guide/libra...okies.html
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#3

And what's next? Cookies are not sent in response. That's the question. I have already read the guide
Reply
#4

(This post was last modified: 08-03-2023, 06:05 AM by kenjis.)

Oh, it is indeed hard to understand how to send cookies in this document.
Reply
#5

I recommend you use Cookie helper.
https://codeigniter.com/user_guide/helpe...elper.html
Reply
#6

ok, i use native setcookie(). But the question is how to use the built-in library? I see there is a CookieStore dispatch() method marked as deprecated 
PHP Code:
$cookie = new Cookie('key''value', [
    'expires'  => new Time('+30 days'),
]);

setcookie($cookie->getPrefixedName(), $cookie->getValue(), $cookie->getOptions()); 
Reply
#7

See https://github.com/codeigniter4/CodeIgniter4/pull/7778
Reply
#8

See https://codeigniter4.github.io/CodeIgnit...ng-cookies
Reply
#9

I answered the question above ^. It's not critical for me to use something other than CookieStore. I was hoping that he himself should be added to the Response or otherwise.
What about the dispatch() method?
Reply
#10

Don't use the dispatch() method. It will be removed in the future.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB