0

I developed a extension. Now I try to add a model which has a function that returns "hello world".

I tried it like seen here.

app/code/local/Fekete/Newsletter2Go/etc/config.xml

...
<global>
    <models>
        <fekete_newsletter2go>
            <class>Fekete_Newsletter2Go_Model</class>
        </fekete_newsletter2go>
    </models>
...

app\code\local\Fekete\Newsletter2Go\Model\Utilities\Hello.php

<?php
class Fekete_Newsletter2Go_Model_Utilities_Hello
{
    public function hello()
    {
        return "hello world";
    }
}

Call:

echo Mage::getModel("fekete_newsletter2go/Utilities_Hello")->hello();

But it does not work, I executed this in a template and the site does not fully load anymore after inserting the code.

I get:

Fatal error: Call to a member function hello() on boolean in ...app/design/frontend/base/default/template/fekete/Newsletter2Go/partials/unsubscribe/form.phtml on line 28

Where is the mistake?


Full config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Fekete_Newsletter2Go>
            <version>0.1.0</version>
        </Fekete_Newsletter2Go>
    </modules>
    <default>
        <newsletter2go_options>
            <!-- Standard Werte für die Extension festlegen -->
            <general>
                <is_active>0</is_active>
                <max_subscriptions>5</max_subscriptions>
            </general>

            <subscribe_text>
                <success>Sie haben sich erfolgreich angemeldet.</success>
                <error>Leider ist ein Fehler aufgetreten. Bitte überprüfen Sie Ihre Daten.</error>
                <invitation_fail>Ihre Abonnementeinladung ist abgelaufen. Bitte versuchen Sie es erneut.</invitation_fail>
                <double_opt_in>Vielen Dank für die Anmeldung. Wir haben Ihnen eine E-Mail mit einem Bestätigungslink zugeschickt.</double_opt_in>
                <already_subscribed>Sie sind bereits angemeldet.</already_subscribed>
                <invalid_email>Bitte tragen Sie eine gültige E-Mail Adresse ein.</invalid_email>
            </subscribe_text>

            <unsubscribe_text>
                <success>Sie haben sich erfolgreich abgemeldet.</success>
                <error>Leider ist ein Fehler aufgetreten. Bitte überprüfen Sie Ihre Daten.</error>
            </unsubscribe_text>

            <user_backend>
                <description>Sie sind mit folgenden E-Mail Adressen am Newsletter angemeldet:</description>
                <subscribe_text>Anmelden</subscribe_text>
                <unsubscribe_text>Abmelden</unsubscribe_text>
            </user_backend>
        </newsletter2go_options>
    </default>
    <global>
        <helpers>
            <fekete_newsletter2go>
                <class>Fekete_Newsletter2Go_Helper</class>
            </fekete_newsletter2go>
        </helpers>
        <blocks>
            <fekete_newsletter2go>
                <class>Fekete_Newsletter2Go_Block</class>
            </fekete_newsletter2go>
        </blocks>
        <models>
            <fekete_newsletter2go>
                <class>Fekete_Newsletter2Go_Model</class>
            </fekete_newsletter2go>
        </models>

        <!-- Neues Attribut für das Customer Model -->
        <resources>
            <Fekete_Newsletter2Go_setup>
                <setup>
                    <module>Fekete_Newsletter2Go</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </Fekete_Newsletter2Go_setup>
            <Fekete_Newsletter2Go_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </Fekete_Newsletter2Go_write>
            <Fekete_Newsletter2Go_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </Fekete_Newsletter2Go_read>
        </resources>
    </global>
    <frontend>
        <layout>
            <updates>
                <fekete_newsletter2go>
                    <file>fekete/newsletter2go.xml</file>
                </fekete_newsletter2go>
            </updates>
        </layout>
        <routers>
            <fekete_newsletter2go_route>
                <use>standard</use>
                <args>
                    <module>Fekete_Newsletter2Go</module>
                    <frontName>fekete_newsletter2go</frontName>
                </args>
            </fekete_newsletter2go_route>
        </routers>  
    </frontend>
    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <newsletter2go_options>
                                            <title>Custom Configuration Section</title>
                                        </newsletter2go_options>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>
7
  • Please share your full config.xml
    – PЯINCƎ
    Commented Oct 5, 2018 at 14:59
  • @PRINCE, see updated post.
    – Black
    Commented Oct 5, 2018 at 15:05
  • Ok, does your module works well without that model ?
    – PЯINCƎ
    Commented Oct 5, 2018 at 15:06
  • @PRINCE, yes it does work perfectly fine without it.
    – Black
    Commented Oct 5, 2018 at 15:15
  • Code looks ok. Any typos in class or file names?
    – sv3n
    Commented Oct 5, 2018 at 15:25

2 Answers 2

0

In app\code\local\Fekete\Newsletter2Go\Model\Utilities\Hello.php, the class Fekete_Newsletter2Go_Model_Utilities_Hello should extend Mage_Core_Model_Abstract.

That means, your code:

class Fekete_Newsletter2Go_Model_Utilities_Hello

should be:

class Fekete_Newsletter2Go_Model_Utilities_Hello extends Mage_Core_Model_Abstract
2
  • I tried it, but the error stays the same.
    – Black
    Commented Oct 5, 2018 at 14:20
  • Any other ideas?
    – Black
    Commented Oct 5, 2018 at 14:47
0

app/code/local/Fekete/Newsletter2Go/Model/Utilities/Hello.php

<?php
class Fekete_Newsletter2Go_Model_Utilities_Hello extends Mage_Core_Model_Abstract
{
    public function hello()
    {
        return "hello world";
    }
}

Now in your template : (put it in your current theme instead base).

app/design/frontend/{yourTheme}/{themeName}/template/fekete/Newsletter2Go/partials/unsubscribe/form.phtml

<?php $hello = Mage::getModel("fekete_newsletter2go/utilities_hello")->hello(); ?>
<?php echo $hello; ?>

Clean cache.

4
  • No. Mage::getModel() and other business logic doesn't belong to template files. You know better when to use blocks :)
    – sv3n
    Commented Oct 5, 2018 at 16:47
  • 1
    @sv3n is back :) Yes It is better to use a block exemple: $this->->hello() in templates but he want a model, And why No ? we can use a model in templates without problem (I know it is not a good practice), I think his object is not just to create model to say hello, but it just a test, he will use it for something else. I'm pretty sure that you have some Mage::getModel('catalog/product')in template in your projects ?
    – PЯINCƎ
    Commented Oct 5, 2018 at 16:59
  • 1
    Missed you too :) No b/c it does not belong there - if its not for testing. I do not use Mage::getModel in templates.
    – sv3n
    Commented Oct 5, 2018 at 17:29
  • Does not work either. Same error.
    – Black
    Commented Oct 8, 2018 at 7:38

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.