代码之家  ›  专栏  ›  技术社区  ›  Tijo joel

在创建纵断面时覆盖纵断面-Prestashop

  •  2
  • Tijo joel  · 技术社区  · 8 年前

    我想在创建个人资料时添加一个带有个人资料的下拉列表。我使用了覆盖,下拉菜单正确出现并保存在数据库中,但编辑或查看时,它不会使“下拉菜单被选中”。

    还有很多未定义名称、未定义类型的警告。我将分享我的代码:-

        class AdminProfilesController extends AdminProfilesControllerCore
    {
        public function __construct()
        {
            $this->bootstrap = true;
            $this->context = Context::getContext();
            $this->table = 'profile';
            $this->className = 'Profile';
            $this->multishop_context = Shop::CONTEXT_ALL;
            $this->lang = true;
            $this->addRowAction('edit');
            $this->addRowAction('delete');
            $this->addRowActionSkipList('delete', array(1));
    
            // For add a fields via an override of $fields_form, use $fields_form_override
            if (is_array($this->fields_form_override) && !empty($this->fields_form_override)) {
             $this->fields_form[0]['form']['input'] = array_merge($this->fields_form[0]['form']['input'], $this->fields_form_override);
         }
    
         $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->l('Delete selected'),
                'confirm' => $this->l('Delete selected items?'),
                'icon' => 'icon-trash'
                )
            );
    
         $this->fields_list = array(
            'id_profile' => array(
                'title' => $this->l('ID'),
                'align' => 'center',
                'class' => 'fixed-width-xs'
                ),
            'name' => array('title' => $this->l('Name'))
            );
    
         $this->identifier = 'id_profile';
    
         /* Fetch All Profiles*/
         $admin_levels = Profile::adminLevels();
         foreach ($admin_levels as $row) {         
          $values_access[] = array(
            'id' => $row['id_admin'],
            'name' => $this->l($row['admin_level_name']),
            'label' => $this->l($row['admin_level_name']),
            'val' => $row['id_admin']                                
            );
      }
    
      $this->fields_form = array(
        'legend' => array(
            'title' => $this->l('Profile'),
            'icon' => 'icon-group'
            ),
        'input' => array(
            array(
                'type' => 'text',
                'label' => $this->l('Name'),
                'name' => 'name',
                'required' => true,
                'lang' => true,
                ),
            ),
    
        $this->fields_form_override = array(
            array(
                'type' => 'select',
                'label' => $this->l('Access Levels'),
                'name' => 'id_admin',   
                    // 'lang' => true,                 
                'col' => '4',                   
                'options' => array(
                    'query' => $values_access,
                    'id' => 'id',
                    'name' => 'name',
                    'val' => 'val'
                    ),
                ),
            ),
    
    
        'submit' => array(
            'title' => $this->l('Save'),
            )
        );
    
      $list_profile = array();
      foreach (Profile::getProfiles($this->context->language->id) as $profil) { 
        $list_profile[] = array('value' => $profil['id_profile'], 'name' => $profil['name']);
    }
    
    parent::__construct();
    }
    
    
    
    }
    

    在Classes文件夹中

    Profile.php

    class Profile extends ProfileCore
    {
        /** @var string Name */
        public $name;
        public $id_admin;
    
        /**
         * @see ObjectModel::$definition
         */
        public static $definition = array(
            'table' => 'profile',
            'primary' => 'id_profile',
            'multilang' => true,
            'fields' => array(
                /* Lang fields */
                'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
                'id_admin' => array('type' => self::TYPE_INT, 'lang' => true)           
                ),
            );
    
        /** Fetching Admin Access Levels */
        public static function adminLevels()
        {
            $access_level = Db::getInstance()->ExecuteS('SELECT *  FROM '._DB_PREFIX_.'admin_levels');
            return $access_level;
        }
    }
    

    配置文件结构与默认值相同。profile_lang结构更改 id\u lang int(10)无符号

    名称varchar(128)

    1 回复  |  直到 8 年前
        1
  •  1
  •   sadlyblue    8 年前

    尝试仅使用:

    $this->fields_form_override = array(
                array(
                    'type' => 'select',
                    'label' => $this->l('Access Levels'),
                    'name' => 'id_admin_level',   
                    'lang' => true,                 
                    'col' => '4',                   
                    'options' => array(
                        'query' => $values_access,
                        'id' => 'id',
                        'name' => 'name',
                        'val' => 'val'
                        ),
                    ),
            );
    

    如果您检查它的使用位置:

    // For add a fields via an override of $fields_form, use $fields_form_override
    if (is_array($this->fields_form_override) && !empty($this->fields_form_override)) {
         $this->fields_form[0]['form']['input'] = array_merge($this->fields_form[0]['form']['input'], $this->fields_form_override);
    }
    

    另一种解决方案是将名称更改为 $this->fields_form_override $this->fields_form parent::__construct(); AdminController::__construct()