Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:13:15+00:00 2026-06-17T22:13:15+00:00

As the title suggests, Here’s the code… public function index(Request $request, Application $app) {

  • 0

As the title suggests,

Here’s the code…

public function index(Request $request, Application $app)
{
    $cookies = $request->cookies;
    print_r($request->cookies);
    if(!$cookies->has("recordsPerPage"))
    {
        $response = new Response();
        $cookie = new Cookie("recordsPerPage", $app['defaultRecordsPerPage']);
        $response->headers->setCookie($cookie); 
    }
    print_r($request->cookies);exit; //prints nothing here !!
}

I also tried to set it in a $app->after() but failed. do you have any other ways to set cookies other than in controller.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:13:17+00:00Added an answer on June 17, 2026 at 10:13 pm

    Cookies are set with response and available on next request. So you have to return the response with this cookie, and if you want it to be available on the request, make it a redirect response so the browser will set cookie and issue next request with this newly created cookie:

    $cookies = $request->cookies;
    if(!$cookies->has("recordsPerPage"))
    {
        $cookie = new Cookie("recordsPerPage", $app['defaultRecordsPerPage']);
        $response = Response::create('', 302, array("Location" => "http://127.0.0.1/whatever/"));
        $response->headers->setCookie($cookie);
        return $response;
    }else{
        return print_r($cookies, 1);
    }
    

    Other possibility is to set this cookie directly in the request ($request->cookies->set('recordsPerPage', $app['defaultRecordsPerPage']);) but you still have to return response with this cookie to set it in the browser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Google News has API, described here: http://code.google.com/apis/newssearch/v1/index.html But it is a JavaScript API (client
Here's the fiddle: http://jsfiddle.net/scZtb/1/ Be warned, as the title suggests, this might crash your
As the title suggests is it possible to execute another java app from within
As the title suggests I cannot log into my CakePHP application with IE. Same
I'm using Smarty with CodeIgniter. Here's my code: <!doctype html> <html lang=en-gb> <head> <title>Frustrating
Suppose I have following code: public class CBase: AbstractC,IRenderable { //code here } public
As the title suggests, I am trying to create a function in Actionscript 2
As the title suggests, we have a Java (Swing) desktop application, and we'd like
Exactly what the title suggests: I perform an ajax request to my server, it
As the title suggests! Here are the relevant files/configs: $ gem list --local ***

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.