Life Lei Dog thinkphp Project----Mall 10 product attribute Management

Source: Internet
Author: User

We usually do the project before the analysis of business logic first, this time is no exception.

Attr_type: Refers to the type of attribute, with a unique, single, and multiple selection of

The unique attribute is the extended attribute that users can see when they purchase a product as shown in the following:

A single-selection attribute, which means that the user does not need to select an extended attribute when purchasing, otherwise it cannot be purchased, as follows:

Multiple selection and radio are the corresponding, but can choose more than one, but only select a single, otherwise it will not be able to buy.

Attr_input_type: Refers to the way properties are entered, with text boxes, drop-down lists, and text fields, as shown in:

Attr_value: Refers to an optional value that should be provided if the property is in a drop-down form.

If the property is in the form of a drop-down list, several of the optional values must be provided, as shown, if the other input methods are empty.

Plainly attr_type is provided to ordinary users, Attr_input_type is generally used for the background administrator.

The location of the extended property in the entire commodity module currently holds the property itself, not the attribute value of a particular commodity.

Once you understand the structure and logic of the table, the next step is to write the code.

First create a AttriburtModel.class.php on the model layer to validate him,

<? php    namespace Admin\model;      Use Think\model;     class extends model{        // automatic validation rule        protected$_validateArray  (            thearray(' attr_name ', ' require ', ' attribute name is not a null '),        );    }

The next step is to write the controller, as shown in the code below:

<?php namespace Admin\controller;  UseThink\controller; classAttributecontrollerextendscommoncontroller{ Public functionindex () {$this-display (); }         Public functionAdd () {if(is_post) {//Warehousing                $data[' attr_name '] = I (' Attr_name '); $data[' type_id '] = I (' type_id '); $data[' attr_type '] = I (' Attr_type '); $data[' attr_input_type '] = I (' Attr_input_type '); $data[' attr_value '] = I (' Attr_value '); $attrModel= D (' attribute '); if($attrModel->create ($data)){                    //by verifying                    if($attrModel-Add ()) {                        $this-Success (' Add property Success ', U (' Index '), 1); }Else{                        $thisError (' Add property failed '); }                }Else{                    //failed to pass validation, prompt for error message                    $thisError ($attrModel-GetError ()); }                return; }            //get all types of goods            $types= M (' Goods_type ')Select (); $thisAssign (' Types ',$types); $this-display (); }         Public functionedit () {$this-display (); }         Public functiondel () {$this-display (); }    }

The next step begins to write the add.html template, as shown in the code below:

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >class= "Action-span" ><a href= "Index.php?p=admin&c=attribute&a=index" > Product Properties </a></span>< Spanclass= "Action-span1" ><a href= "index.php?act=main" >shop Admin Center </a> </span><span id= "search_id"class= "Action-span1" >-add Attribute </span><div style= "Clear:both" ></div>class= "Main-div" > <form action= "" method= "Post" name= "Theform" onsubmit= "return Validate ();" > <table width= "100%" id= "general-table" > <tbody><tr> <tdclass= "Label" > property name:</td> <td> <input type= "text" name= "Attr_name" value= "" size= "+" > <spanclass= "Require-field" >*</span> </td> </tr> <tr> <tdclass= "Label" > Product type:</td> <td> <select name= "cat_id" onchange= "Onchangegoodstype (this.value) "> <option value=" 0 "> Please select ...</option> <volist name=" Types "id=" VO "> &lt ; option Value= "{$vo[' type_id ']} " >{$vo[' Type_name ']} </option> </volist> </select> <spanclass= "Require-field" >*</span> </td> </tr> <tr id= "attrgroups" style= "Display:none;" > &LT;TDclass= "label" > attribute group:</td> <td> <select name= "Attr_group" > </select&gt        ; </td> </tr> <tr> &LT;TDclass= "label" ><a href= "Javascript:shownotice (' Noticeattrtype ')," title= "Click here to view the message" ></a> property optional </td> <td> <label><input type= "Radio" name= "Attr_type" value= "0" checked= "true" > Unique properties </label> <la Bel><input type= "Radio" name= "Attr_type" value= "1" > Single-select Properties </label> <label><input type= "Radi O "name=" Attr_type "value=" 2 "> Check properties </label> <br><spanclass= "Notice-span" style= "Display:block" id= "Noticeattrtype" > select "Radio/Check attribute", you can set multiple values for the product, and also can specify different price markup for different attribute values. When a user buys a product, they need to select a specific attribute value. When you select Unique property, only one value can be set for the property value of the product, and the user can only view the value. </span> </td> </tr> <tr> <tdclass= "Label" > The value of this property input method:</td> <td> <label><input type= "Radio" name= "Attr_input_type" va Lue= "0" checked= "true" onclick= "radioclicked (0)" >Manual Entry</label> <label><input type= "Radio" name= "Attr_input_type" value= "1" onclick= "radioclicked (1)" >Select from the list below (one row represents an optional value)</label> <label><input type= "Radio" name= "Attr_input_type" value= "2" onclick= "radioclicked (0)" >Multi-line text box</label> </td> </tr> <tr> <tdclass= "label" > Optional Value list:</td> <td> <textarea name= "Attr_value" cols= "" rows= "5" disabled= "> </textarea> </td> </tr> <tr> <td colspan= "2" > <divclass= "Button-div" > <input type= "Submit" value= "OK"class= "button" > <input type= "reset" value= "reset"class= "button" > </div> </td> </tr> </tbody></table> <input type= "Hidden" name= "act" value= "Insert" > <input type= "hidden" name= "attr_id" value= "0" > </form></div> <div id= "Footer" >All rights reserved&Copy; 2014-2016 Life Rei Pangdo-Technical summary-</div></div><script type= "Text/javascript" >/** * Toggle option Disabled When clicking the Type button*/functionradioclicked (n) {document. forms[' theform '].elements["attr_value"].disabled = n > 0?false:true;}</script></body>

Life Lei Dog thinkphp Project----Mall 10 product attribute Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.