Maki92
Maki92

Reputation: 441

Cannot use string offset as an array

I am a trainee now. I am continue doing a a project left by last semester trainee. I found out he did a code as below :

 $auth = $this->Auth->User();
    if(!empty($auth)) {
        $auth['User']['is_admin'] = $this->inGroup('admin');

Can anyone teach me how to avoid this error ? Thank you.

Upvotes: 1

Views: 936

Answers (2)

aifarfa
aifarfa

Reputation: 3939

the error indicates that you parse string into array expected function

eg.

$this->inGroup(array('admin')); //check out its function definition for valid parameters.

Upvotes: 1

sikander
sikander

Reputation: 2286

You can check if $auth is an array.

 if(!empty($auth) && is_array($auth) && isset($auth['User'])) {

Upvotes: 1

Related Questions