Create custom model on front-end module in magento

Note:- you can download code from this rar_image
Note:-1) Firstly Disable the all cache from Cache Management tab in System tab.
2) select the default theme of the magento from the System->Design.

Step1:- Create Mywork_Usemodel.xml file in app/etc/modules/.
where Mywork is Namespace and Usemodel is Modulename.

<?xml version="1.0"?>
<config>
    <modules>
        <Mywork_Usemodel>
            <active>true</active>
            <codePool>local</codePool>
        </Mywork_Usemodel>
    </modules>
</config>

Note:- 1) If you want to active the extensions then use true otherwise false.
2) there are three code pool (a) local (b) core (c) community
when we create the own extension then we use local code pool.

Step2:- Now create the config.xml file in app/code/local/Mywork/Usemodel/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mywork_Usemodel>
            <version>1.0.0</version>
        </Mywork_Usemodel>
    </modules>

    <frontend>
        <routers>
            <usemodel>
                <use>standard</use>
                <args>
                    <module>Mywork_Usemodel</module>
                    <frontName>usemodel</frontName>
                </args>
            </usemodel>
        </routers>
        
        <layout>
            <updates>
                <usemodel>
                    <file>usemodel.xml</file>
                </usemodel>
            </updates>
        </layout>
   </frontend>	
  
  <global>
      <blocks>
            <usemodel>
                <class>Mywork_Usemodel_Block</class>
            </usemodel>
        </blocks>
		
        <models>
            <usemodel>
                <class>Mywork_Usemodel_Model</class>
                <resourceModel>usemodel_mysql4</resourceModel>
            </usemodel>
            <usemodel_mysql4>
                <class>Mywork_Usemodel_Model_Mysql4</class>
                <entities>
                    <getadmin>
                        <table>admin_user</table>
                    </getadmin>
                </entities>
            </usemodel_mysql4>
        </models>
    </global>
  </config>

Note:- 1) In this file we created version of this module is 1.0.0
2) In the frontend tag we created routers tag. In routers tag we define the frontend name is usemodel,
and we access the extension value from siteurl/usemodel.

Step3:- Now we create the IndexController.php in app/code/local/Mywork/Usemodel/controllers/IndexController.php

<?php
class Mywork_Usemodel_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
    		
    	$this->loadlayout();
        $this->renderlayout();
   }
    
}
?>

Step4:- Now create the Usemodel.php in app/code/local/Mywork/Useblock/Block/Usemodel.php

<?php
class Mywork_Usemodel_Block_Usemodel extends Mage_Core_Block_Template
{
	
    public function _prepareLayout()
    {
    	
		return parent::_prepareLayout();
    }
    
    
}

Step5:- Now create the Getadmin.php in app/code/local/Mywork/Usemodel/Model/Getadmin.php

<?php

class Mywork_Usemodel_Model_Getadmin extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('usemodel/getadmin');
    }
}

Step6:- Now create the Getadmin.php in app/code/local/Mywork/Usemodel/Model/Mysql4/Getadmin.php

<?php

class Mywork_Usemodel_Model_Mysql4_Getadmin extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {    
        // Note that the user_id refers to the key field in your database table.
        $this->_init('usemodel/getadmin', 'user_id');
    }
    
}

Step7:- Now create the Collection.php in app/code/local/Mywork/Usemodel/Model/Mysql4/Getadmin/Collection.php

<?php

class Mywork_Usemodel_Model_Mysql4_Getadmin_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
 	   public function _construct()
	   {
		parent::_construct();
		$this->_init('usemodel/getadmin');
	   }
}

Step8:- Now create the usemodel.xml in app/design/frontend/default/default/layout/usemodel.xml

<?xml version="1.0"?>
<layout version="1.0">
   <usemodel_index_index>
		<reference name="content">
            <block type="usemodel/usemodel" name="usemodel" template="usemodel/usemodel.phtml" />
        </reference>
    </usemodel_index_index>
</layout>

Step9:- Now create the usemodel.phtml in app/design/frontend/default/default/template/usemodel/usemodel.phtml

<?php
$admin_userModel = Mage::getModel('usemodel/getadmin')->load(1);
echo $admin_userModel->firstname;
echo $admin_userModel->lastname;
?>

Note:- call the url
siteurl/usemodel Output:- Johnkumar