This is my model Class


class Magentotutorial_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract
protected function _construct()

My question is What does this code do in magento?



It initiates the resource model this model uses to commit data to the database.

So in this case that would be the file app/code/[local|community]/Magentotutorials/Weblog/Model/Resource/Blogpost.php

[EDIT] to answer @easymoden00b question, the _init method can be found in Mage_Core_Model_Abstract which directly calls _setResourceModel in the same class

 * Set resource names
 * If collection name is ommited, resource name will be used with _collection appended
 * @param string $resourceName
 * @param string|null $resourceCollectionName
protected function _setResourceModel($resourceName, $resourceCollectionName=null)
    $this->_resourceName = $resourceName;
    if (is_null($resourceCollectionName)) {
        $resourceCollectionName = $resourceName.'_collection';
    $this->_resourceCollectionName = $resourceCollectionName;

This stores the Resource item and collection class names for further use when retrieving and writting to and from the database

  • 1
    related: what does the _init() function do? – easymoden00b Dec 17 '14 at 13:47
  • @easymoden00b made an edit :) – Sander Mangel Dec 17 '14 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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