adrub Posted April 28, 2011 Share Posted April 28, 2011 Hi Everyone!I wanted to add into my shop editable list of distributors.So I created table in db: create table ps2_distributors( ID_distributors int not null auto_increment, Name varchar(100), Country varchar(100), Province varchar(30), City varchar(100), Address varchar(200), Telephone varchar(100), Email varchar(100), Website varchar(200), PRIMARY KEY(ID_distributors) ); And I added a new tab in admin panel.Then I created my class in AdminDistributors.php class AdminDistributors extends AdminTab { function __construct() { $this->table = 'distributors'; $this->className = 'Distributors'; $this->edit = true; $this->delete = true; $this->fieldsDisplay = array( 'Name' => array('title' => $this->l('Name'), 'width' => 160), 'City' => array('title' => $this->l('City'), 'width' => 160), 'Province' => array('title' => $this->l('Province'), 'width' => 160), 'Country' => array('title' => $this->l('Country'), 'width' => 160) ); parent::__construct(); } And it works really nice. I see a grid with my distributors.But then I added: public function displayForm($isMainTab = true) { global $currentIndex; parent::displayForm(); echo $this->className; $obj = $this->loadObject(true); echo ' tralala'; } It's for displaying add and edit mode.And the result is that:echo shows ClassName: "Distributors",but then I see nothing.I realised, that function loadObject is in AdminTab.phpin line: ~1402 elseif ($opt) { echo 'Load3 '; echo $this->className; $this->_object = new $this->className(); return $this->_object; } I see "Load 3", and className: "Distributors"there is something wrong with $this->_object = new $this->className(); And I see on my add page nothing else.I suppose that I should add some information about my table in any others files, or I did something wrong with mysql (auto_increment?)Can someone help me.I use PrestaShop 1.3.1.1 actualy on my local windows 7. Link to comment Share on other sites More sharing options...
adrub Posted April 28, 2011 Author Share Posted April 28, 2011 Please help me.This is function LoadObject from AdminTab.php. protected function loadObject($opt = false) { if ($id = intval(Tools::getValue($this->identifier)) AND Validate::isUnsignedId($id)) { if (!$this->_object) $this->_object = new $this->className($id); if (!Validate::isLoadedObject($this->_object)) die (Tools::displayError('object cannot be loaded')); return $this->_object; } elseif ($opt) { echo '1'; echo $this->className; $this->_object = new $this->className(); echo '2'; return $this->_object; } else { die(Tools::displayError('object cannot be loaded')); } } When I click "add new" I see "1" , "Distributors" (classname) but in the next line is some error.Why?className is correct, so why it does'nt want to create new object? Why it works correctly with other tables?Maybe I didn't add some information in one of the php files? Something about my class? Should I do it somewhere?Please help me. It's really important for me. Link to comment Share on other sites More sharing options...
adrub Posted April 28, 2011 Author Share Posted April 28, 2011 So, please try answer for this questions:What exactly do this line: $this->_object = new $this->className(); ?How does it know how to create new object with className - Distributors?And what does it need to work correctly? Link to comment Share on other sites More sharing options...
joglon Posted May 6, 2011 Share Posted May 6, 2011 Hi,I am also trying to create a module and therefore I am plunging into the working of PS (testsite is 1.3.7).In your _construct method you are refering to function __construct() { $this->table = 'distributors';$this->className = 'Distributors'; $this->edit = true; $this->delete = true; When you instruct PS to create a object, it is looking for a file named "className.php" , in your case "Distributors.php" but only in the directory /classes!else it gives you an error. At least that's what I found out. Link to comment Share on other sites More sharing options...
ramble Posted June 12, 2011 Share Posted June 12, 2011 Does anyone solve it? The classes doesnt help to me. Link to comment Share on other sites More sharing options...
girlvietcode Posted March 13, 2012 Share Posted March 13, 2012 Hi there, I don't know you has the answer or not, but I would like to reply here for other people that have the same issue. In AdminDistributors.php, add following function function myautoload($className) { $className = str_replace(chr(0), '', $className); $moduleDir = dirname(__FILE__).'/'; $file_in_module = file_exists($moduleDir.$className.'.php'); if ($file_in_module) require_once($moduleDir.$className.'.php'); } Then, at the end of your module constructor (in function __construct() ) add line: $this->myautoload($this->className); Now, you can load the class from your module dir. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now