1

I make a new module which is a simply form, but i can not write into the ddbb, because (i think) can not find the model. I have this code in controllers/IndexController.php:

public function createPersonAction() {
    $data = $this->getRequest()->getPost();
    $session = Mage::getSingleton('core/session');
    $landing = Mage::getModel('landing/landing');
    $landing->setData('name', $data['name']);
    $landing->setData('apellido1', $data['apellido1']);
    $landing->setData('apellido2', $data['apellido2']);
    $landing->setData('email', $data['email']);
    $landing->setData('telefono', $data['telefono']);
    //$person->setData($data);
  try{
    $landing->save();
    $session->addSuccess('Add a person sucessfully');
  }catch(Exception $e){
    $session->addError('Add Error');
  }
$this->_redirect('landing');
}

But i have this error:

Fatal error: Call to a member function setData() on boolean in \app\code\local\LP\Landing\controllers\IndexController.php on line 28

(Line 28 is --> $landing->setData('name', $data['name']);)

I have all the needed files, this is my tree:

\app\code\local\LP\Landing\Block\Index.php
\app\code\local\LP\Landing\Block\Adminhtml\Landingbackend.php
\app\code\local\LP\Landing\controllers\IndexController.php
\app\code\local\LP\Landing\controllers\Adminhtml\LandingbackendController.php
\app\code\local\LP\Landing\etc\config.xml
\app\code\local\LP\Landing\Helper\Data.php
\app\code\local\LP\Landing\Model\Landing.php
\app\code\local\LP\Landing\Model\Resource\Landing.php
\app\code\local\LP\Landing\Model\Resource\Landing\Collection.php
\app\code\local\LP\Landing\sql\landing_setup\mysql4-install-0.1.0.php

Help please.

1

It looks like you might have a problem in your module's config.xml file.

It should look something like this:

<global>
    <models>
        <landing>
            <class>LP_Landing_Model</class>
            <resourceModel>landing_resource</resourceModel>
        </landing>
        <landing_resource>
            <class>LP_Landing_Model_Resource</class>
            <entities>
                <landing>
                    <table>lp_landing_db_tablename</table>
                </landing>
            </entities>
        </landing_resource>
    </models>
    <resources>
        <landing_write>
            <connection>
                <use>core_write</use>
            </connection>
        </landing_write>
        <landing_read>
            <connection>
                <use>core_read</use>
            </connection>
        </landing_read>
        <lp_landing_setup>
            <setup>
                <module>LP_Landing</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </lp_landing_setup>
    </resources>
</global>

You'll obviously need to change the <table>lp_landing_db_tablename</table> table name to whatever you specified in your LP/Landing/sql/lp_landing_setup/mysql4-install-0.1.0.php file.

You also may need to rename your install file from mysql4-install-0.1.0.php to install-0.1.0.php for Magento to properly run the setup script.

0

Yes, great!

The lines that declared the table of the database were missing

        <entities>
            <landing>
                <table>lp_landing_db_tablename</table>
            </landing>
        </entities>

Thank you very much.

  • No problem. I'm glad you're back on track. – duttyman Feb 10 '17 at 12:14

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.