The code in the add_post event knows what data to receive and how to verify that the data can be roughly understood at the first glance. Therefore, it is concluded that this method uses the TP 3.2 framework.
Public function add_post () {// verification rule $ rule = array ('name', 'require ', 'Enter name', 1 ), // name must be verified); $ m = M ('user'); // Obtain the name, sex, and contact data to the model, and verify if (! $ M-> field ('name, sex, contact ')-> validate ($ rule)-> create ()) $ this-> error ($ m-> getError (); $ result = $ m-> add (); if (! $ Result) $ this-> error ('add failed'); $ this-> success ('added successfully', U ('dir '));}
Verification rules can also be written to the model, but I feel a little troublesome. first, sometimes different page verification methods are used, and second, the code in this add_post event is displayed, it is clear what data to receive and how to verify that the data can be roughly understood at the first glance, so this method is summarized.