by Adam Brett

Class 'String' not found in app/Model/User.php on line xx

This article was published on Tuesday, July 17, 2012 which was more than 18 months ago , this means the content may be out of date or no longer relevant. You should verify that the technical information in this article is still current before relying upon it for your own purposes.

This is a really easy to fix error that occurs in a very specific situation. Namely when developing an application in CakePHP that makes use of the ACL behavior whilst also having a beforeSave method on the User model. It can be pretty frustrating at first because there's nothing about it on the Internet, and as far as you can tell, there isn't an error on line xx, and you're not using the String object anywhere.

It's happening because of a missing options array on the beforeSave method you added to the User model. Simply change:

<?php
    public function beforeSave() {

to

<?php
    function beforeSave($options = array()) {

and make sure that you call parent::beforeSave($options) somewhere in your method definition.

For exclusive content, including screen-casts, videos, and early beta access to my projects, subscribe to my email list below.


I love discussion, but not blog comments. If you want to comment on what's written above, head over to twitter.