Thinkphp with associated model Has_many.
Use, create ProductModel.class.php under the Model folder
The code is as follows:
<?phpnamespace test\model;<span style= "color: #FF0000;" >use think\model\relationmodel;</span>class ProductModel extends <span style= "color: #FF0000;" >relationmodel</span>{ Protected $_link = Array (' attr ' =>array (' mapping_type ' = Self::has_many, ' Class_name ' + ' attr ', ' foreign_key ' = ' product_id ', ' mapping_name ' = ' a ', //used to fetch data ' mapping_fields ' ' Id,name,value ',//' as_fields ' = ' id,name,value ',);}
How to use the controller:
Public Function testrelation () { $postData = I (' post. '); Dump ($postData);d ie; $productModel = D ("test/product"); $data [' name '] = $postData [' Phone_name ']; $data [' thumb '] = $photo [0]; $data [' thumb '] = ' KK '; $data [' create_time '] = time (); <span style= "color: #FF0000;" > $data [' A ']= array ( //Here is a two-dimensional array because it is the Has_many model array (' name ' = ' = ' color ', ' value ' = > Serialize ($postData [' Phone_color ')), Array ( ' name ' = ' = ' size ', ' value ' = = $ postdata[' phone_size '),</span> ); $result = $productModel->relation (True)->add ($data); Dump ($result); exit; }
thinkphp Correlation Model