2

This is the content of my controller:

<?php
class Attin_Exportdb_Adminhtml_AttributesController extends Mage_Adminhtml_Controller_Action{

    public function IndexAction() {

        $this->loadLayout();
        $this->getLayout()->getBlock("head")->setTitle($this->__("Export Attributes"));

        $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','attributes_exp_db',array('template' => 'exportdb/attributes.phtml'));
        $this->getLayout()->getBlock('content')->append($block);

        $this->renderLayout(); 

    }
    public function AjaxAction(){

        $model = Mage::getModel('exportdb/attrdb')->query_attr();
        echo $model;
    }
}

This is the content of my model:

<?php

class Attin_Export_Model_Attrdb extends Mage_Core_Model_Abstract
{

   public function query_attr(){
        return "Test";
   }

}

and this is the config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Attin_Exportdb>
            <version>0.1.0</version>
        </Attin_Exportdb>
    </modules>
    <global>
        <helpers>
            <exportdb>
                <class>Attin_Exportdb_Helper</class>
            </exportdb>
        </helpers>
        <blocks>
            <exportdb>
                <class>Attin_Exportdb_Block</class>
            </exportdb>
        </blocks>
        <models>
            <exportdb>
                <class>Attin_Exportdb_Model</class>
            </exportdb>
        </models>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <attin_exportdb before="Mage_Adminhtml">Attin_Exportdb_Adminhtml</attin_exportdb>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

My question in AjaxAction() function what am I doing wrong ? thx in advance

  • Thx a lot for both of you !!! – Attila Naghi Nov 12 '14 at 7:47
  • Please dont make a question updation based on the answer given here unless it was an error when you prepare the question.It will ruin the intergrity of the answer. You can edit the content and "beautify" it ofcourse. Hope you will understand. – Rajeev K Tomy Nov 12 '14 at 7:50
  • yes, sure, sorry – Attila Naghi Nov 12 '14 at 7:58
4

As per the your configuration , your model class name is wrong. It should be Attin_Exportdb_Model_Attrdb instead of Attin_Export_Model_Attrdb

More Details

Your configuration is looks like this

   <models>
        <exportdb>
            <class>Attin_Exportdb_Model</class>
        </exportdb>
    </models>

So when you call a model like this Mage::getModel('exportdb/someModel'), then Magento first trace which module holds exportdb as its model alias name. In this case Magento will find Attin_Exportdb.

Now Magento will trace the model location from <class> node. So in your case it is Attin_Exportdb_Model.

Again Magento uses someModel in order to generate the rest class name. In this case it will append to the previous value. So the class that magento expects become Attin_Exportdb_Model_SomeModel and Magento expects this class in the location

 app/code/<codePool>/Attin/Exportdb/Model/SomeModel.php
  • Thx a lot , my mistake !!! – Attila Naghi Nov 12 '14 at 7:40
  • Don't think he's suggesting change from Exportdb to Export, he's pointing out that in your question the class name uses just Export – Jonathan Hussey Nov 12 '14 at 7:44
  • @JonathanHussey: I gave a description. – Rajeev K Tomy Nov 12 '14 at 7:45
6

There are issue in Issue 1:

<model> should be <models> .It magento logic .please check at config.xml

So

<model>
            <exportdb>
                <class>Attin_Exportdb_Model</class>
            </exportdb>
        </model>

Should be

<models>
            <exportdb>
                <class>Attin_Exportdb_Model</class>
            </exportdb>
        </models>

Issue2:

Also your issue in model class name it should be

Attin_Exportdb_Model_Attrdb instead of Attin_Export_Model_Attrdb As you module dir is

Attin_Exportdb which define at config.xml

 <Attin_Exportdb> <!-- this path of module -->
            <version>0.1.0</version>
        </Attin_Exportdb>

Please check how to Call model and block and create an extension

http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/

  • Yup, everything else looks fine. – thebluefox Nov 12 '14 at 7:34
  • I changed to models, but I still get this error message: <b>Fatal error</b>: Call to a member function query_attr() on a non-object in <b>/home/netlogiq/public_html/CUSTOM/attin/ef/app/code/local/Attin/Exportdb/controllers/Adminhtml/AttributesController.php</b> on line <b>19</b><br /> – Attila Naghi Nov 12 '14 at 7:35
  • Have you cleared the cache after changing? – Andreas von Studnitz Nov 12 '14 at 7:38
  • @Amit Bera Thx a lot – Attila Naghi Nov 12 '14 at 7:41

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.