Since you're using multiple models in your controller (the $uses var),
I think Cake is just getting confused. On construct, it probably pulls
the model name from the controller name (like how you used
Inflector::singularize()) before it loads models. Then, in the actions
it probably pulls the first model in the $uses array because the
models have been loaded. In this case, Log.

I would recommend against the $uses array unless absolutely necessary.
Use App::import() to bring it in, or ClassRegistry::init() to load it
when needed. Or bind the Log model to your Ship one, if appropriate.

In any case, try moving 'Ship' to the first item of the $uses array
and see if that works. I'd say this method is still unreliable.

hth



On Apr 20, 3:54 am, Leonid Mamchenkov <[email protected]> wrote:
> 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 sitehttp://cakeqs.organd 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 
> athttp://groups.google.com/group/cake-php?hl=en

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