CakePHP 1.3 Import Method

Hey i'm new to php pie. I want to use one model in another model, then we can use the $ uses method. this method is very simple. we can also do the same with App :: import ("Controller", "Users") ;? if so, tell me how?

+4
source share
1 answer

Yes, you can, but not with the $uses property, since the model does not have it.

Take a look at this definition of $uses :
An array containing the names of the model classes that this controller uses.

So this means that $uses is a Controller property, not a Model one.

It is now possible to use one model functionality in another. This is what is for Model Associations . For example, if you have the following:
The recipe belongs to the user and the opposite association (for example): The user hasMany Recipe (the user can have several recipes.) From both of these models, you could call other methods:
From user model: $this->Recipe->find('all'); will search the recipe table. You can also call any custom methods defined in another model.

If the two models do not have a specific association, you can snap on the fly. You can read all about these features in CakePHP - 1.3 or 2.x.

And friendly advice. I see that you are posting this question with cakephp1.3 tag. If you're a beginner, I highly recommend starting to learn CakePHP 2.x because this version:
1. newest
2. has the most “object approach”
3. it is one that will develop even more (not that 1.3 is not supported or something else)

+1
source

All Articles