Hello,

I came across a weird behaviour that I cannot figure out.  The API
documentation for Controller class (http://api.cakephp.org/class/
controller) describes the modelClass property in the following way:

"This controller's primary model class name, the
Inflector::classify()'ed version of the controller's $name property.
Example: For a controller named 'Comments', the modelClass would be
'Comment'"

This sounds exactly like what I need.  However, when I try to use, it
doesn't always work this way.  Maybe because my controller is using
several models, and the "primary" model is not the first one in the
list.

class ShipsController extends AppController {
  var $name = 'Ships';
  var $uses = array('Log', 'Ship');

  function __construct() {
    parent::__construct();
    # die($this->modelClass); # prints out 'Ship' and dies, as
expected
  }

  function index() {
    die($this->modelClass); # prints out 'Log' and dies. Why Log?
  }
}

I first noticed the problem using CakePHP 1.2.4.  I upgraded to
CakePHP 1.2.6, but the problem is still there.  I checked and re-
checked all my ShipsController and AppController code to make sure I
don't modify the modelClass or any related logic.

Can anyone shed some light on this issue?

I can avoid this issue altogether by always putting the primary model
of the controller as first item of the $uses list, or call
Inflector::singularize($this->name), but it doesn't sound elegant,
since the functionality is there and should work.

Thanks.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to