FilChi Weblog

how to call models in cakephp 1.2 custom components?

Posted on: August 27, 2008

I was able to connect again to cakephp irc community yesterday about 1pm already, Philippines time. Another fellow cakephp programmer asked about how to call or include models in custom components.

I told him you can use,


so, after a while, he told me the code worked. I also explained to him that the uses() is deprecated in 1.2.

And then, another programmer told us about using ClassRegistry::init() in custom components. He provided us a link so we can see more explanation about using the code.

I post this blog because the way of Incorporating models in components is making me confused. You suggest using App::import and then , another will say use ClassRegistry. But when you suggest ClassRegistry, someone will say, just use App::import. I don’t get it.

5 Responses to "how to call models in cakephp 1.2 custom components?"

I think it is a matter of preference which approach you use to access a model from within a component. With App::import you have to manually instantiate the model with “new”, whereas this is done automatically with ClassRegistry::init(). Personally, I prefer App::import as it is more expressive.

Hi Daniel, thanks for your comment!
actually, whether it is a matter of preference or following what the book says is another issue I initially wanted to blog about.
Which is better then? Is it really intended to have more than one way to incorporate models in components?

I don’t know which approach is better, you might have to ask one of the devs…

I need to call a model method in my component.
I added “App::import(‘Model’,);” at the top of component.
When i call a function in my model within my component it shows error.
Please tell me how to call a function in model within my component

what is the synatax to call a function of model

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Flickr Photos

%d bloggers like this: