# |
Jun 22nd 2021, 11:16 |
neon1024 |
imeanimsureitcouldbelongerifwejustaddedsomemorenestedmethodsintotherebutyoucantbetoocarefullthesedaysyouknow |
# |
Jun 22nd 2021, 11:16 |
kevin.pfeifer |
,:) |
# |
Jun 22nd 2021, 11:16 |
neon1024 |
`$this->setRequest($this->getRequest()->withCookieCollection($this->getRequest()->getCookieCollection()->add($cookie)));` oof |
# |
Jun 22nd 2021, 11:15 |
slackebot1 |
'pages', 'action' => 'display', 'success' ] );``` |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
``` // Only save cookie if user selected it if(!empty($data['remember_my_data'])){ $cookie = Cookie::create( 'remember_my_data', $data ); $this->response = $this->response->withCookie( $cookie ); } else { $this->response = $this->response->withExpiredCookie(new Cookie('remember_my_data')); } return $this->redirect( [ 'controller' => |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
I don’t return the response instance, i just do a redirect |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
or whatever |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
before redirecting |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
could be that you need to adjust the returned cookie collection as well |
# |
Jun 22nd 2021, 11:14 |
neon1024 |
…and return that response instance I suppose? |
# |
Jun 22nd 2021, 11:14 |
kevin.pfeifer |
but you need to set it back into the response as well |
# |
Jun 22nd 2021, 11:14 |
kevin.pfeifer |
well your code above returns the new cookie collection |
# |
Jun 22nd 2021, 11:13 |
neon1024 |
Not an intuitive api for sure imho |
# |
Jun 22nd 2021, 11:12 |
neon1024 |
I wonder what all this CookieCollection business is about then :thinking_face: |
# |
Jun 22nd 2021, 11:12 |
kevin.pfeifer |
i did it like that |
# |
Jun 22nd 2021, 11:12 |
neon1024 |
I guess it just dies when the request instance does |
# |
Jun 22nd 2021, 11:12 |
kevin.pfeifer |
``` $cookie = Cookie::create( 'remember_my_data', $data ); $this->response = $this->response->withCookie( $cookie );``` |
# |
Jun 22nd 2021, 11:10 |
neon1024 |
`$this->getRequest()->getCookieCollection()->add($cookie);` I’ve tried this and no cookie shows in my browser debug tools |
# |
Jun 22nd 2021, 11:10 |
neon1024 |
Stupid question but how do I write a cookie which will persist across requests? |
# |
Jun 22nd 2021, 10:21 |
kevin.pfeifer |
even if it is tidious |
# |
Jun 22nd 2021, 10:21 |
kevin.pfeifer |
otherwise I would personally just go from error to error till it works ^^ |
# |
Jun 22nd 2021, 10:20 |
drashti.b.patel |
ok will check thanks for the help |
# |
Jun 22nd 2021, 10:19 |
neon1024 |
Ahh, just found `$this->getRequest()->getSession()->id()` |
# |
Jun 22nd 2021, 10:19 |
kevin.pfeifer |
never done it myself so no promises :shrug: |
# |
Jun 22nd 2021, 10:18 |
kevin.pfeifer |
but I have heard that it can be quite finicky to setup |
# |
Jun 22nd 2021, 10:18 |
kevin.pfeifer |
there is a rector tool which partially upgrades your code https://book.cakephp.org/4/en/appendices/4-0-upgrade-guide.html |
# |
Jun 22nd 2021, 10:17 |
drashti.b.patel |
Or Is there any shortcut or any command line to update it |
# |
Jun 22nd 2021, 10:16 |
neon1024 |
I was looking at `Session::create()` but doesn’t seem to be it |
# |
Jun 22nd 2021, 10:16 |
drashti.b.patel |
In most of the controller I have used the initialize() function Do I need to set the return param every where? |
# |
Jun 22nd 2021, 10:16 |
neon1024 |
Anyone know how I can restore / reconnect to a session by using the ID from the Cookie? |
# |
Jun 22nd 2021, 10:15 |
drashti.b.patel |
public function middleware($middlewareQueue) and when I fixed it to public function middleware($middlewareQueue): MiddlewareQueue |
# |
Jun 22nd 2021, 10:14 |
kevin.pfeifer |
which does not have the same parameters as the core one |
# |
Jun 22nd 2021, 10:14 |
kevin.pfeifer |
your `src/Application.php` has a middleware function |
# |
Jun 22nd 2021, 10:14 |
kevin.pfeifer |
yes, you now need to adjust your code according to the errors shwon |
# |
Jun 22nd 2021, 10:13 |
slackebot1 |
Fatal error: Declaration of App\Application::middleware($middlewareQueue) must be compatible with Cake\Http\BaseApplication::middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueue in /var/www/html/cp-kickpages/src/Application.php on line 72``` |
# |
Jun 22nd 2021, 10:13 |
drashti.b.patel |
It worked for the installation but after that when I tried to run application showing below error: Child process error (exit code 255): PHP Fatal error: Declaration of App\Application::middleware($middlewareQueue) must be compatible with ``` Cake\Http\BaseApplication::middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueue in /var/www/html/cp-kickpages/src/Application.php on line 72 |
# |
Jun 22nd 2021, 10:09 |
drashti.b.patel |
ok |
# |
Jun 22nd 2021, 10:09 |
kevin.pfeifer |
try to remove the composer.lock and vendor folder and then re-install everything with ```composer install``` |
# |
Jun 22nd 2021, 10:08 |
kevin.pfeifer |
|
# |
Jun 22nd 2021, 10:04 |
slackebot1 |
"minimum-stability": "stable", "prefer-stable": true } |
# |
Jun 22nd 2021, 10:04 |
slackebot1 |
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests", "Elements\\Test\\": "./plugins/Elements/tests", "Admin\\": "plugins/Admin/src/" } }, "scripts": { "post-install-cmd": "App\\Console\\Installer::postInstall", "post-create-project-cmd": "App\\Console\\Installer::postInstall", "//post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump" }, |