Prestashop对象模型返回null值

时间:2015-02-24 08:44:57

标签: php mysql prestashop prestashop-1.6 object-model

大家好,有人可以帮我这个,我正在尝试使用Prestashop Objectmodel类来添加,删除,更新和查看数据库中的数据,我已经实现了检索数据并在后台表单上显示它,同时单击编辑按钮/删除它从backoffice点击删除选项但坚持保存或更新它,这是我的代码

班级档案

<?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),
		)
	);
}

这是我渲染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)));
	}

以下是处理它的代码

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;
		}

	}

这是我的数据库结构:

CREATE TABLE IF NOT 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文本NOT NULL,   image varchar(255)NOT NULL,   name varchar(255)NOT NULL,   rank varchar(255)NOT NULL,   主要关键(id_blocktesti) )ENGINE = InnoDB DEFAULT CHARSET = utf8 AUTO_INCREMENT = 1;

CREATE TABLE IF NOT NOT EXISTS ps_blocktesti_lang(   id_blocktesti int(11)NOT NULL,   id_shop int(10)NOT NULL,   id_lang int(10)NOT NULL,   text文本NOT NULL,   PRIMARY KEY(id_shopid_lang) )ENGINE = InnoDB DEFAULT CHARSET = utf8;

任何帮助都将受到高度赞赏,提前谢谢。

PS注意我正在使用blockcmsinfo进行上述项目。

0 个答案:

没有答案