Jump to content

[SOLVED] making own ObjectModel class doesn't work


Recommended Posts

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 by dhobo (see edit history)
Link to comment
Share on other sites

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

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 :D

 

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

×
×
  • Create New...