Ideas:
1, different products belong to different types, such as: mobile phones, clothing, computers and other types
2. Different types have different attributes, which are divided into unique attributes and optional attributes, such as clothing: Optional attribute {size: s,m,l ...; Color: white, black ... } Unique Properties: Material
First, associate the type with the attribute.
1. Build a table
Type table {P39_type}
if exists p39_type;create table P39_type ( null auto_increment comment ' Id ', type_name varchar (null comment ' type name ', key (ID)) enginedefault Charset=utf8 comment ' type ';
property sheet {P39_attribute}
drop tableifexists p39_attribute;create table P39_attribute (id mediumint unsigned notNULLAuto_increment comment ' Id ',attr_name varchar (() notNULLComment ' attribute name ',attr_type enum (' Unique ', ' optional ') notNULLComment ' attribute type ',attr_option_values varchar () notNULL default"comment" attribute optional value, separated by commas multiple values ',type_id mediumint unsigned unsigned notNULLComment ' belongs to type ',PrimaryKey(ID),Keytype_id (type_id)) engine=innodbdefaultCharset=utf8 Comment ' attribute table ';
2. GII automatically generates two-sheet operation codes
Attention:
1, before generating the type table code, in the configuration file p39_type.php, be careful to add verification that checks whether the type name is duplicated, and does not require the search function "type data level is small"
2 , before generating the property sheet code, in the configuration file P39_arrtribute, delete the unnecessary search field
3. Adjust the generated code to make it more suitable
1, the type changed to drop-down box, applicable to the pre-packaged drop-down function buildselect (' table name ', ' drop-down box name ', ' drop-down box ' value [table field] ', ' table field text ', ' optional value ')
functionBuildselect ($tableName,$selectName,$valueFieldName,$textFieldName,$selectedValue= ' ') { $model= D ($tableName); $data=$model->field ("$valueFieldName,$textFieldName")->select ();//take two field values as needed $select= "<select name="$selectName' ><option value= ' > Please select </option> ";//The drop-down box name is stored in the table field foreach($data as $k=$v) { $value=$v[$valueFieldName];//Value <= field value "Table ID" $text=$v[$textFieldName];//Display content <= field value Store content if($selectedValue&&$selectedValue==$value)//decide whether to select $selected= ' selected= ' selected "'; Else $selected= ' '; $select. = ' <option '.$selected. ' Value= '.$value.‘" > '.$text.‘ </option> '; } $select. = ' </select> '; Echo $select; }
2, the property optional value of the Chinese comma case processing
Delete Type
When you delete a type, all properties under the corresponding type are deleted
idea: Delete all properties {_before_delete ()} before deleting the type code TypeModel.class.php execution
PHP.38-TP Framework Mall Application Example-backstage 15-commodity properties vs. stock 1-Different products (unique attributes, optional attributes), property type