4

I want to know About what is _init() do in magento?

$this->_initSometext();
1

1 Answer 1

12

There are 2 different things.

_init
_init from a collection model sets the model class for the collection items. So each item in the collection will be an instance of the class passed to the _init method.

_init in a model, sets the resource model class instance used for that model.
_init in a resource model class sets the main table and the primary key associated to the resource model.

_initSomeText
_initSometext() has no special meaning. There are a lot of these methods defined all over the code and serve different purposes depending on the class. It's just like any other method in the class. The fact that it starts with _init means that probably initializes something.
For example; Mage_Adminhtml_Catalog_CategoryController::_initCategory reads the request, sets some data for the page layout, and loads the requested category.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.