1

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.

3
  • What is the error, exactly? Commented Mar 27, 2012 at 3:41
  • He posted the error as the question title: "Cannot use string offset as an array" Commented Mar 27, 2012 at 3:42
  • Fatal error: Cannot use string offset as an array, the $auth is a string. Someone told me string cannot be used this way, and I don't know why the last trainee did like this. I just continue his project, and I am still figuring how it works. Commented Mar 27, 2012 at 3:44

2 Answers 2

1

You can check if $auth is an array.

 if(!empty($auth) && is_array($auth) && isset($auth['User'])) {
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for helping me, although I don't really understand, but the fatal error is now gone, it proceeded to next error " AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => User [Aro0.foreign_key] => 2 ) " "
1

the error indicates that you parse string into array expected function

eg.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.