0

Created a module for front-end to show data from custom table but it is showing a blank page.

Here is the config.xml file:

<?xml version="1.0"?>
<config>
<modules>
    <MageSf_OrderCustom>
        <version>1.0.1</version>
    </MageSf_OrderCustom>
</modules>
<global>
    <blocks>
        <magesf_ordercustom>
            <class>MageSf_OrderCustom_Block</class>
        </magesf_ordercustom>
        <ordercustom>
            <class>MageSf_OrderCustom_Block</class>
        </ordercustom>
    </blocks>

    <helpers>
        <ordercustom>
            <class>MageSf_OrderCustom_Helper</class>
        </ordercustom>
    </helpers>

    <models>         
        <magesf_ordercustom>
            <class>MageSf_OrderCustom_Model</class>
            <resourceModel>magesf_ordercustom_resource</resourceModel>
        </magesf_ordercustom>
        <magesf_ordercustom_resource>
            <class>MageSf_OrderCustom_Model_Resource</class>
            <entities>
                <ordercustom>
                    <table>magesf_ordercustom</table>
                </ordercustom>
            </entities>
        </magesf_ordercustom_resource>
    </models>

    <resource>
        <magesf_ordercustom_setup>
            <setup>
                <module>MageSf_OrderCustom</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </magesf_ordercustom_setup>
        <magesf_ordercustom_write>
            <connection>
                <use>core_write</use>
            </connection>
        </magesf_ordercustom_write>
        <magesf_ordercustom_read>
            <connection>
                <use>core_read</use>
            </connection>
        </magesf_ordercustom_read>
    </resource>
</global>       
<adminhtml>
   <layout>
        <updates>
            <ordercustom>
                <file>magsf_ordercustom.xml</file>
            </ordercustom>
        </updates>
    </layout>
</adminhtml>
<frontend>    
    <layout>
        <updates>
            <ordercustom>
                <file>ordercustom.xml</file>
            </ordercustom>
        </updates>
    </layout>
</frontend>
<frontend>
    <routers>
        <ordercustom>
            <use>standard</use>
            <args>
                <module>MageSf_OrderCustom</module>
                <frontName>ordercustom</frontName>
            </args>
        </ordercustom>
    </routers>  
</frontend>
<admin> 
<routers>
     <adminhtml> 
         <args> 
             <modules> 
                <MageSf_OrderCustom after="Mage_Adminhtml">MageSf_OrderCustom_Adminhtml</MageSf_OrderCustom> 
            </modules> 
        </args>
   </adminhtml>        
</routers> 
</admin>
</config>

Here is the layout xml file for my module:

<?xml version="1.0"?>
 <layout version="0.1.0">
   <customer_account>        
      <reference name="customer_account_navigation">           
        <action method="addLink" translate="label" module="ordercustom">
           <name>ordercustom</name>
           <path>ordercustom/customer/view</path>
           <label>Order Attachments</label>
        </action>
      </reference>
   </customer_account>   

 <ordercustom_customer_view> 
    <update handle="customer_account"/> 
        <reference name="content">    
            <block type="ordercustom/customer" name="view.ordercustom" template="ordercustom/customer/view.phtml"/> 
        </reference> 
 </ordercustom_customer_view>
</layout>

And My controller file is as follows:

<?php


 class MageSf_OrderCustom_CustomerController extends   Mage_Core_Controller_Front_Action
  {    

  public function preDispatch()
{
       parent::preDispatch();

       if (!Mage::getSingleton('customer/session')->authenticate($this))    {
        $this->setFlag('', 'no-dispatch', true);

    // adding message in customer login page
    Mage::getSingleton('core/session')
            ->addSuccess(Mage::helper('ordercustom')->__('Please sign in or create a new account'));
    }
  }            
/**
 * View Your Module
 */

public function viewAction() {

  $this->loadLayout();   
  $this->getLayout()->getBlock("head")->setTitle($this->__("Order Attachments"));
        $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
  $breadcrumbs->addCrumb("home", array(
            "label" => $this->__("Home Page"),
            "title" => $this->__("Home Page"),
            "link"  => Mage::getBaseUrl()
       ));

  $breadcrumbs->addCrumb("titlename", array(
            "label" => $this->__("Attachments"),
            "title" => $this->__("Attachments")
       ));

  $this->renderLayout(); 


     }
   } 
?>

My Block code is as :

<?php


 class MageSf_OrderCustom_Block_Customer extends Mage_Core_Block_Template
 {
 public function view()
 {
    echo "Hello World";
    $data = Mage::getModel('magesf_ordercustom/ordercustom')->load();

    $collection = $data->getCollection();
    return $collection;

   }

}

?>

And at last my model looks like follows:

<?php

  class MageSf_OrderCustom_Model_Ordercustom extends Mage_Core_Model_Abstract
  {
     public function _construct()
       {
         parent::_construct();
         $this->_init('magesf_ordercustom/ordercustom');
       }
  }
 ?>

View.phtml file just printing the whole collection:

<?php 

    $collection = $this->view();
        print_r($collection);

 ?>

enter image description here

Can anyone just check where i have done wrong and how i can fix it to show the data from my custom table.

7
  • 2
    Please add content for your file ordercustom/customer/view.phtml to question. Mar 22, 2017 at 8:40
  • Updated the question: i am just printing the whole collection for now
    – Zoo
    Mar 22, 2017 at 8:43
  • please make sure you have your phtml file located at app/design/frontend/YourPackage/YourTheme/template/ordercustom/customer/view.phtml or app/design/frontend/base/default/template/ordercustom/customer/view.phtml Mar 22, 2017 at 9:05
  • ohhhhh. Got it thanks for getting me out of this... it was misspell in folder name. "ordercutom".. thanks
    – Zoo
    Mar 22, 2017 at 9:11
  • You're welcome, Please add it as your answer and accept it so it can help others facing similar issue. Mar 22, 2017 at 9:22

1 Answer 1

0

in your block class change code as below , because in your code you load the model and then call collection, I think that is not right

<?php


 class MageSf_OrderCustom_Block_Customer extends Mage_Core_Block_Template
 {
 public function view()
 {
    echo "Hello World";
    $data = Mage::getModel('magesf_ordercustom/ordercustom');

    $collection = $data->getCollection();
    return $collection;

   }

}

?>

and also remove below code from your config.xml

    <magesf_ordercustom>
        <class>MageSf_OrderCustom_Block</class>
    </magesf_ordercustom>
3
  • Still the same issue. thanks for responding.
    – Zoo
    Mar 22, 2017 at 8:49
  • @Shoaib check updated code Mar 22, 2017 at 8:52
  • Nope its doing the same. showing the same blank page. @Murtuza Zabuawala
    – Zoo
    Mar 22, 2017 at 8:57

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.