PraveenShahi Posted February 24, 2015 Share Posted February 24, 2015 Hello everyone can someone help me on this, i am trying to use Prestashop Objectmodel class for Adding, Deliting, Updating and Viewing Data from database, i have achieved retrieving data and displaying it on backoffice Form while clicking Edit button / deliting it from backoffice by clicking Delete option but stuck on saving or Updating it, here is my codes Class file <?php class TestiBlock extends ObjectModel { public $id_blocktesti; public $id_lang; public $id_shop; public $testi; public $image; public $name; public $rank; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'blocktesti', 'primary' => 'id_blocktesti', 'multilang' => true, 'fields' => array( 'id_lang' =>array('type' => self::TYPE_NOTHING), 'id_shop' =>array('type' => self::TYPE_NOTHING), 'testi' => array('type' => self::TYPE_HTML), 'image' => array('type' => self::TYPE_STRING), 'name' => array('type' => self::TYPE_STRING), 'rank' => array('type' => self::TYPE_STRING), ) ); } here is my code for rendering Form protected function renderForm() { $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('New Testimonial'), 'image' => '../img/admin/tab-categories.gif', ), 'input' => array( array( 'type' => 'hidden', 'name' => 'id_blocktesti', ), array( 'type' => 'file', 'label' => $this->l('Profile Picture'), 'name' => 'image', 'required' => false, 'hint' => $this->l('Upload a image from your computer.').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)' ), array( 'type' => 'text', 'label' => $this->l('Person\'s Name'), 'required' => false, 'name' => 'name', 'hint' => $this->l('Name of The Person made testimony.') ), array( 'type' => 'text', 'label' => $this->l('Designation or Rank'), 'required' => false, 'name' => 'rank', 'hint' => $this->l('Degignation, Rank or Job Title of person.') ), array( 'type' => 'textarea', 'label' => $this->l('Testimonial'), 'required' => false, 'lang' => false, 'name' => 'testi', 'cols' => 40, 'rows' => 10, 'class' => 'rte', 'autoload_rte' => true, ), ), 'submit' => array( 'title' => $this->l('Save'), ), 'buttons' => array( array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 'title' => $this->l('Back to list'), 'icon' => 'process-icon-back' ) ) ); if (Shop::isFeatureActive() && Tools::getValue('id_blocktesti') == false) { $fields_form['input'][] = array( 'type' => 'shop', 'label' => $this->l('Testimonial association'), 'name' => 'checkBoxShopAsso_theme' ); } $helper = new HelperForm(); $helper->module = $this; $helper->name_controller = 'blocktesti'; $helper->identifier = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); foreach (Language::getLanguages(false) as $lang) $helper->languages[] = array( 'id_lang' => $lang['id_lang'], 'iso_code' => $lang['iso_code'], 'name' => $lang['name'], 'is_default' => ($default_lang == $lang['id_lang'] ? 1 : 0) ); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; $helper->toolbar_scroll = true; $helper->title = $this->displayName; $helper->submit_action = 'saveblocktesti'; $helper->fields_value = $this->getFormValues(); return $helper->generateForm(array(array('form' => $fields_form))); } and here is code for processing it public function getContent() { $id_info = (int)Tools::getValue('id_blocktesti'); if (Tools::isSubmit('saveblocktesti')) { $info = new TestiBlock((int)$id_info); $info->save(); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } elseif (Tools::isSubmit('updateblocktesti') || Tools::isSubmit('addblocktesti')) { $this->html .= $this->renderForm(); return $this->html; } else if (Tools::isSubmit('deleteblocktesti')) { $info = new TestiBlock((int)$id_info); $info->delete(); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else { $this->html .= $this->renderList(); return $this->html; } } and here is my db structure: CREATE TABLE IF NOT EXISTS ps_blocktesti ( id_blocktesti int(2) unsigned NOT NULL AUTO_INCREMENT, id_lang int(10) unsigned NOT NULL DEFAULT '1', id_shop int(2) unsigned NOT NULL, testi text NOT NULL, image varchar(255) NOT NULL, name varchar(255) NOT NULL, rank varchar(255) NOT NULL, PRIMARY KEY (id_blocktesti) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; CREATE TABLE IF NOT EXISTS ps_blocktesti_lang ( id_blocktesti int(11) NOT NULL, id_shop int(10) NOT NULL, id_lang int(10) NOT NULL, text text NOT NULL, PRIMARY KEY (id_blocktesti) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Any help would be highly appreciated, thanks in advance. PS Note i am using blockcmsinfo module for above project. Link to comment Share on other sites More sharing options...
Szed Posted March 25, 2016 Share Posted March 25, 2016 Hello ! I am trying to do the same thing, but get null in database too... Any luck ? 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