Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » 2.3 RC2 and cookie problem

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 950 Views
  • toddm
    Avatar
    Community Member
    15 Posts

    2.3 RC2 and cookie problem Link to this post

    Hi,

    I'm trying to upgrade to 2.3 RC2 and have problem setting cookies.

    <?php

    class AbstractContent_Controller extends ContentController {
       function init() {
          parent::init();
    Cookie::set('country', 'example');
    }
    }
    ?>

    And then there are controllers that extend AbstractContent_Controller

    Use to work fine in 2.2.2

    Error:

    Line 21 in /public/silverstripe/sapphire/core/Cookie.php
    Source

    12     * @param name The variable name
    13     * @param value The variable value. May be an array or object if you wish.
    14     * @param expiryDays The expiry time, in days. Defaults to 90.
    15     */
    16    static function set($name, $value, $expiryDays = 90) {
    17       if(!headers_sent($file, $line)) {
    18          $expiry = $expiryDays > 0 ? time()+(86400*$expiryDays) : 0;
    19          setcookie($name, $value, $expiry, Director::baseURL());
    20       } else {
    21          if(self::$report_errors) user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
    22       }
    23       $_COOKIE[$name] = $value;
    24    }
    25    
    26    /**
    27     * Get a cookie variable

    Trace

    * Cookie 'country' can't be set. The site started outputting was content at line 1 in /public/silverstripe/mysite/code/zipconfig.php
    Line 21 of Cookie.php
    * Cookie::set(country,175)
    Line 17 of AbstractContent.php
    * AbstractContent_Controller->init()
    Line 131 of LandingPage4ButtonsWithCategories.php
    * LandingPage4ButtonsWithCategories_Controller->init()
    Line 112 of Controller.php
    * Controller->handleRequest(HTTPRequest)
    Line 19 of ModelAsController.php
    * ModelAsController->handleRequest(HTTPRequest)
    Line 257 of Director.php
    * Director::handleRequest(HTTPRequest,Session)
    Line 106 of Director.php
    * Director::direct(americas)
    Line 111 of main.php

    Any ideas?

    950 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.