0

i've a problem with accessing my model class. I just want to access the class Test and execute the function getGnarf but everytime i try, i get the error "Fatal error: Call to a member function getGnarf() on a non-object".

The Test Class:

<?php 
class Tools_Webservice_Model_Test {
    function getGnarf() {
        return "Zoor";
    }
}
?>

I don't need to extend the class with the Mage_COre_Model_Abstract because of no DB functionality is needed ?

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Tools_Webservice>
            <version>0.1.0</version>
        </Tools_Webservice>
    </modules>
    <global>
        <modules>
            <webservice>
                <class>Tools_Webservice_Model</class>
            </webservice>
        </modules>
        <helpers>
                <webservice>
                        <class>Tools_Webservice_Helper</class>
                </webservice>
        </helpers>
    </global>
</config>

The calling class:

require_once '../app/Mage.php';
Mage::app('default');

$model = Mage::getModel('webservice/test');              
echo $model->getGnarf();  // leads to fatal error 

Thx for your help !

  • Try adding public to the getGnarf() declaration. Also check if you get an instance of the model inside $model with a var_dump() – mbalparda Feb 3 '15 at 12:13
2

Inside the global node, you have modules, I think you meant models. Other than that it looks about right.

  • We've all done it I'm sure. I've spent hours debugging typos in the past. – Peter O'Callaghan Feb 3 '15 at 16:08
0

You have not properly define in module there issue inn

Issue 1:

should be .It magento logic .please check at config.xml

So

<model>
            <webservice>
                <class>Tools_Webservice_Model</class>
            </webservice>
        </model>

Should be

<models>
            <webservice>
                <class>Tools_Webservice_Model</class>
            </webservice>
        </models>

If you have define block and helper and model the then you need define <blocks>...</blocks>,<helpers>.... </helpers>,<models>..<models> with proper object type

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.