我在向cms页面添加自定义字段时遇到了一些问题,我覆盖了CMS.php和AdminCmsController.php
class CMS extends CMSCore
{
public $page_image;
public $text_uno;
public $text_due;
public $text_tre;
public static $definition = array(
'table' => 'cms',
'primary' => 'id_cms',
'multilang' => true,
'multilang_shop' => true,
'fields' => array(
'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'position' => array('type' => self::TYPE_INT),
'indexation' => array('type' => self::TYPE_BOOL),
'active' => array('type' => self::TYPE_BOOL),
/* Lang fields */
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 3999999999999),
'text_uno' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 3999999999999),
'text_due' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 3999999999999),
'text_tre' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 3999999999999),
'page_image' => array('type' => self::TYPE_STRING, 'lang' => false, 'validate' => 'isString', 'size' => 3999999999999),
),
);
}
这里是AdminCmsController.php
class AdminCmsController extends AdminCmsControllerCore
{
public function renderForm()
{
.....
array(
'type' => 'textarea',
'label' => $this->l('Testo uno'),
'name' => 'text',
'autoload_rte' => true,
'lang' => true,
'rows' => 5,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
array(
'type' => 'text',
'label' => $this->l('Testo due'),
'name' => 'text_due',
'autoload_rte' => true,
'lang' => true,
'rows' => 5,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
array(
'type' => 'text',
'label' => $this->l('Testo tre'),
'name' => 'text_tre',
'autoload_rte' => true,
'lang' => true,
'rows' => 5,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
.....
}
public function postProcess()
{
$languages = Language::getLanguages(false);
$update_images_values = false;
foreach ($languages as $lang)
{
if (isset($_FILES['page_image']) && isset($_FILES['page_image']['tmp_name']) && !empty($_FILES['page_image']['tmp_name']))
{
if ($error = ImageManager::validateUpload($_FILES['page_image'], 40000000)){
return $error;
}
else
{
$ext = substr($_FILES['page_image']['name'], strrpos($_FILES['page_image']['name'], '.') + 1);
$file_name = md5($_FILES['page_image']['name']).'.'.$ext;
if (!move_uploaded_file($_FILES['page_image']['tmp_name'],_PS_IMG_DIR_ .'cms'.DIRECTORY_SEPARATOR.$file_name)){
return Tools::displayError($this->l('An error occurred while attempting to upload the file.'));
}
else
{
$values['page_image'][$lang['id_lang']] = $file_name;
}
}
$update_images_values = true;
$cms = new CMS((int)Tools::getValue('id_cms'));
$cms->page_image = $file_name;
$cms->update();
}
}
parent::postProcess();
}
我能够保存图片而不能保存其他文本字段,错误在哪里?