Welcome to FindNerd,today we are going to discuss bindModel and unbindModel function in CakePHP 2.X.
If we are making any web application in CakePHP then sometimes we have to use bindModel and unbindModel at a runtime. So CakePHP provides inbuilt function of bindModel() and unbindModel. This function will bind Model at the runtime and also help to fetch data with association.
Let explain one by one
1-bindModel():- This function is used for creating association between models as per our need in our CakePHP web application.
In below example we can see there are 3 model Country, State and city and we want to fetch all state data based on country because a country has many state and also we want all city based on a state because a state has many city.
2:-UnbindModel()- This function is used for destroying the created association if we have no longer required.
Suppose we are making a web application in CakePHP and we have many tables in our web application and we have a lot of association between them for fetching data from multiple tables. But Sometimes we don't need that data longer so for destroying association we will use unBind function for unbinding models.
We can see below example how destroy the association