I have created a custom component in Joomla 2.5. In this component I want to fetch all the user ‘s are available in com_users.For this I want you to know, How can i use com_users model class in to my component. Any one have suggestion’s to how to do it.
I have created a custom component in Joomla 2.5 . In this component I
Share
Depending on where you want use the model you can simply ask Joomla! to load it for you.
In a
JControllerclass or sub-class you can callgetModelpassing in the model name and the components prefix…e.g.
It may be necessary to add the path of the external model you want to load using
JModel::addIncludePath()as show above.Or if you’re sure of the model name and the class prefix you could use
JModel‘sgetInstance()to create the desired model object… e.g.Alternatively in a view you could:
N.B. In the first line we’re passing our desired models name, normally you call
getModelwithout any params to load the default model for your components view controller. In the second line, as we’re only passing the model tosetModel()it won’t make it the default model the view uses.When we want to use our model objects later on we can specify which we want to use like this:
The first line uses the view’s default model (because we have specified one in the optional parameter). The second line uses the
getItem()frommyOtherModel.That’s all works because
JView(inlibraries/joomla/application/view.php) has these methods: