Search code examples
magentomagento-1.8

Magento Model Rescource


I am a newbie with Magento. I have a problem with Model Rescource of Magento.

This is config.xml

<config>
<Magentotutorial_Weblog>
    <version>0.0.1</version>
</Magentotutorial_Weblog>
<frontend>
    <routers>
        <weblog>
            <use>standard</use>
            <args>
                <module>Magentotutorial_Weblog</module>
                <frontName>weblog</frontName>
            </args>
        </weblog>
    </routers>
</frontend>
<global>
    <models>
        <weblog>
            <class>Magentotutorial_Weblog_Model</class>
            <resourceModel>weblog_resource</resourceModel>
        </weblog>
        <weblog_resource>
            <class>Magentotutorial_Weblog_Model_Resource</class>
            <entities>
                <blogpost>
                    <table>blog_posts</table>
                </blogpost>
            </entities>
        </weblog_resource>
    </models>
    <resources>
        <weblog_setup>
            <setup>
                <module>Magentoturorial_Weblog</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </weblog_setup>
        <weblog_write>
            <connection>
                <use>core_write</use>
            </connection>
        </weblog_write>
        <weblog_read>
            <connection>
                <use>core_read</use>
            </connection>
        </weblog_read>
    </resources>
</global>
   </config>

Model

<?php
class Magentotutorial_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract
{
   protected function _construct()
   {
       $this->_init('weblog/blogpost');
    }
 }
 ?>

Model resource

<?
class Magentotutorial_Weblog_Model_Resource_Blogpost extends  Mage_Core_Model_Resource_Db_Abstract{
protected function _construct()
{
   $this->_init('weblog/blogpost', 'blogpost_id');
}
}
?>

I call $blogpost = Mage::getResourceModel('weblog/blogpost');

This variable of $blogpost return is false; but my screen on browser show "_init('weblog/blogpost', 'blogpost_id');"; I found all code lines, I don't see nolines could show it.

If I comment //$this->_init('weblog/blogpost', 'blogpost_id');, so "_init('weblog/blogpost', 'blogpost_id');" don't appear


Solution

  • It looks like you have PHP short tags turned off on your server, but your model resource file

    <?
    class Magentotutorial_Weblog_Model_Resource_Blogpost extends  Mage_Core_Model_Resource_Db_Abstract{
    protected function _construct()
    {
       $this->_init('weblog/blogpost', 'blogpost_id');
    }
    }
    ?>
    

    Uses a short tag opening/ Change

    <?
    

    to

    <?php
    

    and your immediate problem should be solved.