dhobo Posted August 26, 2013 Share Posted August 26, 2013 (edited) Hi, I have the following own class: <?php class AllNews extends ObjectModel { /** @var string Name */ public $title; public $publish; public $date_publish; public $manual; public static $definition = array( 'table' => 'all_news', 'primary' => 'id', 'fields' => array( 'position' => array('type' => self::TYPE_INT), // Lang fields 'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), ), ); } ?> and I want to use it in my own Module like this: include_once _PS_MODULE_DIR_.'classes/AndareNews.php'; $oNews = new AllNews(); $oNews->title = Tools::getValue('ALL_MSG_TITLE'); $oNews->save(); then I get this error: [PrestaShop] Fatal error in module andarenews: Call to undefined method AndareNews::save() does the save() function not exist anymore? Edited August 26, 2013 by dhobo (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 26, 2013 Share Posted August 26, 2013 you class name is AllNews and you use AndareNews::save() static function moreover, you should use functions like: add(); update(); Link to comment Share on other sites More sharing options...
NemoPS Posted August 26, 2013 Share Posted August 26, 2013 Also, you should add Core as suffix to the name of your class Link to comment Share on other sites More sharing options...
dhobo Posted August 26, 2013 Author Share Posted August 26, 2013 first one was stupid mistake, tried to copy it from another module. fixed that one now. unfortunately that didn't do the trick. Code is now this: allnewscore.php: <?php class AllNewsCore extends ObjectModel { /** @var string Name */ public $title; public $publish; public $date_publish; public $manual; public static $definition = array( 'table' => 'all_news', 'primary' => 'id', 'fields' => array( 'position' => array('type' => self::TYPE_INT), // Lang fields 'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), ), ); } ?> and in my module: include_once _PS_MODULE_DIR_.'classes/AllNews.php'; $oNews = new AllNews(); $oNews->title = Tools::getValue('ALL_MSG_TITLE'); $oNews->add(); error: [PrestaShop] Fatal error in module allnews: Call to undefined method AllNews::add() Link to comment Share on other sites More sharing options...
NemoPS Posted August 26, 2013 Share Posted August 26, 2013 Try adding an Add method which calls parent::Add() Link to comment Share on other sites More sharing options...
vekia Posted August 26, 2013 Share Posted August 26, 2013 you're calling module class add(); function, not your object class. use different class name for your object name and call ModelObject->add(); where ModelObject is a class name of your object (not module!) 1 Link to comment Share on other sites More sharing options...
NemoPS Posted August 26, 2013 Share Posted August 26, 2013 UH! true he used the same name! Do what Vekia said, I didn't notice that Link to comment Share on other sites More sharing options...
dhobo Posted August 26, 2013 Author Share Posted August 26, 2013 vekia, you were right Link to comment Share on other sites More sharing options...
vekia Posted August 26, 2013 Share Posted August 26, 2013 yea, glad that we can help you a little here may i know what module you developing right now? looks like some news system ? Link to comment Share on other sites More sharing options...
dhobo Posted August 26, 2013 Author Share Posted August 26, 2013 yeah I used to figure it out all myself in 1.4, but haven't worked on presta and on PHP for a while, so making very silly mistakes lately. This one was definitely not related to presta at all, just my lack of PHP I guess indeed, news system kinda like how the CMS works. will have some more specific features though, which our client doesn't want me to bring out in the public (yet) Link to comment Share on other sites More sharing options...
Recommended Posts