public function withCookie($name, $data = '')
    {
        if ($name instanceof Cookie) {
            $cookie = $name;
        } else {
            deprecationWarning(
                get_called_class() . '::withCookie(string $name, array $data) is deprecated. ' .
                'Pass an instance of \Cake\Http\Cookie\Cookie instead.'
            );

            if (!is_array($data)) {
                $data = ['value' => $data];
            }
            $data += [
                'value' => '',
                'expire' => 0,
                'path' => '/',
                'domain' => '',
                'secure' => false,
                'httpOnly' => false
            ];
            $expires = $data['expire'] ? new DateTime('@' . $data['expire']) : null;
            $cookie = new Cookie(
                $name,
                $data['value'],
                $expires,
                $data['path'],
                $data['domain'],
                $data['secure'],
                $data['httpOnly']
            );
        }

        $new = clone $this;
        $new->_cookies = $new->_cookies->add($cookie);

        return $new;
    }
public function withCookie($name, $data = '')
    {
        if ($name instanceof Cookie) {
            $cookie = $name;
        } else {
            deprecationWarning(
                get_called_class() . '::withCookie(string $name, array $data) is deprecated. ' .
                'Pass an instance of \Cake\Http\Cookie\Cookie instead.'
            );

            if (!is_array($data)) {
                $data = ['value' => $data];
            }
            $data += [
                'value' => '',
                'expire' => 0,
                'path' => '/',
                'domain' => '',
                'secure' => false,
                'httpOnly' => false
            ];
            $expires = $data['expire'] ? new DateTime('@' . $data['expire']) : null;
            $cookie = new Cookie(
                $name,
                $data['value'],
                $expires,
                $data['path'],
                $data['domain'],
                $data['secure'],
                $data['httpOnly']
            );
        }

        $new = clone $this;
        $new->_cookies = $new->_cookies->add($cookie);

        return $new;
    }
public function withCookie ( $ name , $ data = '' ) { if ( $ name instanceof Cookie ) { $ cookie = $ name ; } else { deprecationWarning ( get_called_class ( ) . '::withCookie(string $name, array $data) is deprecated. ' . 'Pass an instance of \Cake\Http\Cookie\Cookie instead.' ) ; if ( ! is_array ( $ data ) ) { $ data = [ 'value' => $ data ] ; } $ data += [ 'value' => '' , 'expire' => 0 , 'path' => '/' , 'domain' => '' , 'secure' => false , 'httpOnly' => false ] ; $ expires = $ data [ 'expire' ] ? new DateTime ( '@' . $ data [ 'expire' ] ) : null ; $ cookie = new Cookie ( $ name , $ data [ 'value' ] , $ expires , $ data [ 'path' ] , $ data [ 'domain' ] , $ data [ 'secure' ] , $ data [ 'httpOnly' ] ) ; } $ new = clone $ this ; $ new -> _cookies = $ new -> _cookies -> add ( $ cookie ) ; return $ new ; }
Create a new response with a cookie set.

### Data

- `value`: Value of the cookie
- `expire`: Time the cookie expires in
- `path`: Path the cookie applies to
- `domain`: Domain the cookie is for.
- `secure`: Is the cookie https?
- `httpOnly`: Is the cookie available in the client?

### Examples

```
// set scalar value with defaults
$response = $response->withCookie('remember_me', 1);

// customize cookie attributes
$response = $response->withCookie('remember_me', ['path' => '/login']);

// add a cookie object
$response = $response->withCookie(new Cookie('remember_me', 1));
```

@param string|\Cake\Http\Cookie\Cookie $name The name of the cookie to set, or a cookie object
@param array|string $data Either a string value, or an array of cookie options.
@return static
Create a new response with a cookie set .