0

I am trying to get the my custom module on front end from database but it not showing any thing but just the blank module page:

My controller:

  <?php
  class OptFirst_ReviewMyCompany_IndexController extends Mage_Core_Controller_Front_Action{

    public function IndexAction() {

    $this->loadLayout();   
    $this->getLayout()->getBlock("head")->setTitle($this->__("Reviews"));
    $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->__("Reviews"),
        "title" => $this->__("Reviews")
   ));

    $this->renderLayout(); 


  }
}

Here is my block :

 <?php
class OptFirst_ReviewMyCompany_Block_Index extends Mage_Core_Block_Template
    {
     public function index()
    {
        $productId = 1;//change to your product id
        $collection = Mage::getModel('optfirst_reviewmycompany/new_optfirst_reviewmycompany')->getCollection()
         ->addFieldToFilter('id_optfirst_reviewmycompany', $productId);
           return $collection;

   }

}

And this is my module template:

  <?php
$collection = $this->index();
print_r($collection);
foreach ($collection as $instance) {
          echo  $instance['facebook'].'<br>';
          /* you can customize code here */
          }

     ?>  

layout Node review.xml

  <? xml version = "1.0" ?>   
  <layout version="0.1.0">   
     <reviews_index_index>   
       <reference name="root">   
         <action method="setTemplate"><template>page/1column.phtml</template></action>   
       </reference>   
       <reference name="content">   
           <block type="reviews/index" name="reviews_index" template="reviews/index.phtml"/>   
      </reference>   
 </reviews_index_index>   
  </layout> 

here is the front-end template:

enter image description here

Anyone can look and let me know what is the issue:

Thanks!

0

1 Answer 1

1

Try this,

config.xml

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

    <frontend>
    <routers>
      <reviewmycompany>
        <use>standard</use>
          <args>
            <module>OptFirst_ReviewMyCompany</module>
            <frontName>reviewmycompany</frontName>
          </args>
      </reviewmycompany>
    </routers>
        <layout>
          <updates>
            <reviewmycompany>
              <file>reviews.xml</file>
            </reviewmycompany>
          </updates>
        </layout>
  </frontend>

    <global>
        <blocks>
            <reviewmycompany>
                <class>OptFirst_ReviewMyCompany_Block</class>
            </reviewmycompany>
        </blocks>

        <helpers>
            <optfirst_reviewmycompany>
                <class>OptFirst_ReviewMyCompany_Helper</class>
            </optfirst_reviewmycompany>
        </helpers>

        <models>         
            <optfirst_reviewmycompany>
                <class>OptFirst_ReviewMyCompany_Model</class>
                <resourceModel>optfirst_reviewmycompany_resource</resourceModel>
            </optfirst_reviewmycompany>
            <optfirst_reviewmycompany_resource>
                <class>OptFirst_ReviewMyCompany_Model_Resource</class>
                <entities>
                    <review>
                        <table>optfirst_reviewmycompany</table>
                    </review>
                </entities>
            </optfirst_reviewmycompany_resource>
        </models>

        <resource>
            <optfirst_reviewmycompany_setup>
                <setup>
                    <module>OptFirst_ReviewMyCompany</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </optfirst_reviewmycompany_setup>
            <optfirst_reviewmycompany_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </optfirst_reviewmycompany_write>
            <optfirst_reviewmycompany_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </optfirst_reviewmycompany_read>
        </resource>
    </global>

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <optfirst_reviewmycompany after="Mage_Adminhtml">OptFirst_ReviewMyCompany_Adminhtml</optfirst_reviewmycompany>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

    <adminhtml>
        <layout>
            <updates>
                <optfirst_reviewmycompany>
                    <file>optfirst_reviewmycompany.xml</file>
                </optfirst_reviewmycompany>
            </updates>
        </layout>
        <translate>
            <modules>
                <optfirst_reviewmycompany>
                    <files>
                        <default>OptFirst_ReviewMyCompany.csv</default>
                    </files>
                </optfirst_reviewmycompany>
            </modules>
        </translate>
    </adminhtml>

    <default>
        <optfirst_reviewmycompany>
            <general>
                <default_sort_by><![CDATA[position]]></default_sort_by>
            </general>
        </optfirst_reviewmycompany>
    </default>
</config>

reviews.xml

<?xml version = "1.0"?>   
<layout version="0.1.0">   
  <reviewmycompany_index_index> 
    <reference name="root">   
      <action method="setTemplate"><template>page/1column.phtml</template></action>   
    </reference>   
    <reference name="content">   
      <block type="reviewmycompany/index" name="reviewmycompany_index" template="reviews/index.phtml"/>   
    </reference>   
  </reviewmycompany_index_index> 
</layout>   
7
  • no luck : is there any issue with my template that i am using: rwd/default
    – Xabby
    Commented Nov 28, 2016 at 15:54
  • Ok just add <?php echo "Test";?> in your phtml then reload front end it display or not
    – Magento 2
    Commented Nov 28, 2016 at 15:55
  • not displaying anything..
    – Xabby
    Commented Nov 28, 2016 at 15:56
  • then file is a problem you are adding phtml in theme only right
    – Magento 2
    Commented Nov 28, 2016 at 15:57
  • update ur xml file
    – Magento 2
    Commented Nov 28, 2016 at 15: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.