Category: Sessions

Q: Problem when reading an associative array form Cookie

Cakephp returns an error when reading an associative array from Cookie. I have an CRM application that stores some clients data in cookie. 

<?php 

class ClientsController extends AppController {

    public function initialize() {

        parent::initialize();
        $this->loadComponent('Cookie');
    }

    public function getClientName($index) {

        $client = $this->Cookie->read('Client');
        echo $client[$index]['name'];

        $this->viewBuilder()->layout('ajax');
    }

[GET] /clients/get-client-name/0 returns an error:

Warning (2): Illegal string offset 'name' [APP/Controller/ClientsController.php, line 1292]

Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 435
Cake\Http\ActionDispatcher::_invoke() - CORE/src/Http/ActionDispatcher.php, line 122
Cake\Http\ActionDispatcher::dispatch() - CORE/src/Http/ActionDispatcher.php, line 96
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 60
[main] - ROOT/webroot/index.php, line 36
json cookie
0 Answers

Version: 3

No answers yet!

The community needs your help!

Post your Answer

Created: 3 Oct '16

Last Reply: None

Replies: 0

Views: 225

Votes: 0

Welcome to Aero Coding!

Aero Coding is a CakePHP-focused Q&A community for professional and enthusiast cake bakers. It's built and run by you as part of the community.


Join Now Tour

Download Cakephp

Start baking your own CakePHP application!


Cakephp All Versions