1

I am getting Error in my model Fatal error: Class Abhi_Test_Model_Mysql4_Test contains 1 abstract method and must therefore be declared abstract or implement the remaining methods

I have implemented saving form data from front end in controller file as follows

<?php
class Abhi_Test_User_ViewController extends Mage_Core_Controller_Front_Action {
        public function historyAction() {
            echo "Hello it is abhilash";
            $this->loadLayout();    /*This function read all layout files and loads                               them in memory */
            $this->renderLayout();  /* This function processes and displays all layout                             phtml and php files */

        }

        public function savetestAction() {
            $title = $_REQUEST['title'];
            $filename = $_REQUEST['filename'];
            $content = $_REQUEST['content'];
            $status = $_REQUEST['status'];
            try{
                $model = Mage::getModel('test/test');
                $model->setTitle($title);
                $model->setFilename($filename);
                $model->setContent($content);
                $model->setStatus($status);
                $model->setCreatedTime(strtotime(‘now’));
                $model->setUpdatedTime(strtotime(‘now’));
                $model->save();
            } catch(Exception $e) {

            }
            $this->_redirectSuccess('test/user_view/table');
        return $this;
        }

        public function tableAction() {
            $this->loadLayout();    /*This function read all layout files and loads                               them in memory */
            $this->renderLayout();  /* This function processes and displays all layout                             phtml and php files */
        }

    }
?>

This my model class file where i am getting error

<?php
class Abhi_Test_Model_Mysql4_Test extends Mage_Core_Model_Mysql4_Abstract {
    public function _contruct() {
        $this->_init('test/test', 'test_id');   /*here test_id is the primary of the table test. And test/test, is the magento table name as mentioned in the config.xml */
        parent::__construct();
    }

    public function loadByField($field, $value) {
        $table = $this->getMainTable();
        $where = $this->_getReadAdapter()->quoteInto("$field = ?", $value);
        $select = $this->_getReadAdapter()->select()->from($table, array('test_id'))->where($where);
        $id = $this->_getReadAdapter()->fetchOne($sql);
        return $id;
    }

}
?>

Please tell me if I am doing this correct. My from I have put in template.

0

You have to rename

public function _contruct() {

to

protected function _construct() 
{

because of \Mage_Core_Model_Resource_Abstract::_construct declared as abstract.

The error is telling you that this function is missing in your class.

0

Remove the line parent::__construct(); it does nothing anyway.

  • Ok but whats the solution for the error sir – Abhilash Narayan Nov 2 '17 at 13:49
  • this should solve your problem also...I think – Marius Nov 2 '17 at 14:03

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.