Discuss the maintainability and robustness of mvc C and V. This post was last edited by A9925 at 2015-01-1717: 49: 33 mvc. everyone is familiar with it. & nbsp; the basic structure is also quite clear. Today I would like to discuss with you how many methods in a controller in the control layer are suitable, and, can a display layer be called multiple times? (for example, adding a user page or modifying a user page, we will discuss the maintainability and robustness of mvc C and V.
This post was last edited by A9925 on 17:49:33
Everyone is familiar with mvc and understands the basic structure.
I want to discuss with you today,
In the control layer, the number of methods in a controller is appropriate,
And whether a display layer can be repeatedly called (like adding a user page or modifying a user page ).
If a page is added or modified, too many logical judgments will be written in the view to determine whether the control layer is added or modified, the corresponding control layer to which the node is added or modified. (These must be the value of an action at the display layer, or the name attribute, or both get or post to submit these judgments to different control layers .)
It is confusing to maintain an old system.
Paste some code to see the code of the old project, which needs to be improved, because every time you enter a function, you must constantly analyze what the function is doing and maintain it, it is a waste of time to read code. Please kindly advise.
For example, the control layer // writes modifications to members, but some functions are not modifying member data. this is just a file, and the code in other places of the project is similar or even more, each time you enter the method, you need to go through the process to know which to execute and where to jump out. Even jump out of the box, replace view (XXX. php) with the name of a controller, and repeat what I said above to go into another loop analysis code. It is inconvenient to maintain. I hope to give some constructive suggestions on how to handle this idea and what aspects should be paid attention to in the future. thank you.
// ---------------- Modify member data -------------------------------
Public function alterInfo ()
{
$ StrAction = "";
$ Teamname = $ _ SESSION ['teamname'];
If ($ _ GET ){
$ InUserid = $ _ GET ['id'];
$ Data ['userid'] = $ inUserid;
}
If ($ _ POST ){
// Var_dump ($ _ POST );
// Die ();
$ Userid = $ _ POST ['userid'];
$ Mobile = $ _ POST ['mobile'];
$ Realname = $ _ POST ['realname'];
$ Zhengjian = trim ($ this-> input-> post ('zhengjian '));
// $ Idnumber = $ _ POST ['idnumber'];
$ Idnumber = trim ($ this-> input-> post ('idnu '));
$ Address = $ _ POST ['address'];
$ Zipcode = $ _ POST ['zipcode'];
$ Clothsize = $ _ POST ['clothsize'];
$ Data ['strclothopt'] = $ this-> Common_model-> getClothOpy ($ clothsize );
$ Birthday = trim ($ this-> input-> post ('birthday '));
$ Passportnu = trim ($ this-> input-> post ('passportnu '));
$ Gender = trim ($ this-> input-> post ('gender '));
If ($ _ FILES ["idnumscan"] ["error"]> 0)
{
$ Data ['error'] = $ _ FILES ["idnumscan"] ["error"]."
";
$ Userpic = $ _ POST ['idnumscans '];
}
Else
{
$ Data ['filename'] = $ _ FILES ["idnumscan"] ["name"];
$ Data ['filetype'] = $ _ FILES ["idnumscan"] ["type"];
$ Data ['filesize'] = ($ _ FILES ["idnumscan"] ["size"]/1024). "Kb ";
$ Data ['filepath'] = $ _ FILES ["idnumscan"] ["tmp_name"];
$ Excelname = iconv ("UTF-8", "gb2312", $ _ FILES ["idnumscan"] ["name"]);
$ Userpic = $ _ FILES ["idnumscan"] ["name"];
Move_uploaded_file ($ _ FILES ["idnumscan"] ["tmp_name"], "upload/image/". $ excelname );
}
If ($ _ POST ['action'] = "add "){
$ StrAction = $ teamname;
$ Data ['userid'] = "";
// The second to the last digit is male and female.
$ Gender = substr ($ idnumber, 16,1) % 2;
// Var_dump ($ gender );
$ Teamid = $ _ SESSION ['clubid'];
$ Usertype = 0;
$ This-> load-> model ('Member _ Model ');
$ RowIsReg = $ this-> Member_model-> isRegistered ($ idnumber, $ clubid );
If ($ rowIsReg ){
Echo "script" alert ('The ID card number has been registered in this club! ') Script ";
// Redirect (base_url (). "member ");
} Else {
$ Res = $ this-> Member_model-> insMember ($ mobile, $ realname, $ idnumber, $ gender, $ address, $ zipcode, $ clubid, $ usertype, $ userpic, $ clothsize );
If ($ res ){
Echo "script" alert ('the new players have been created! ') Script ";
Redirect (base_url (). "team ");
}
}
}
If ($ _ POST ['action'] = "alert "){
// Var_dump ($ zhengjian );
// Die ();
$ StrAction = $ teamname;
$ Data ['userid'] = $ userid;
If ($ idnumber! = ''And $ zhengjian = '1') {// added or modified with your ID card
// The second to the last digit is male and female.
$ Gender = substr ($ idnumber, 16,1) % 2;
// Var_dump ($ gender );
$ Clubid = $ _ SESSION ['clubid'];
$ Usertype = 0;
$ This-> load-> model ('Member _ Model ');
$ RowIsReg = $ this-> Member_model-> isRegisteredtoo ($ idnumber, $ clubid, $ userid );
If ($ rowIsReg ){
Echo "script" alert ('cannot be changed to ". $ idnumber.". this ID card number has been registered in this club! ') Script ";
// Redirect (base_url (). "member ");
} Else {
$ Res = $ this-> Member_model-> alertMember ($ mobile, $ realname, $ idnumber, $ gender, $ address, $ zipcode, $ clubid, $ usertype, $ userpic, $ clothsize, $ userid, $ birthday, $ passportnu );
If ($ res ){
Echo "script" alert ('Players ". $ realname." data modified successfully! ') Script ";
Redirect (base_url (). "team ");
}
}
} Else {// added or modified with passport
// Echo "111111111111 ";
// Die ();
$ Clubid = $ _ SESSION ['clubid'];
$ Usertype = 0;
$ Res = $ this-> Member_model-> alertMemberpassportnu ($ mobile, $ realname, $ idnumber, $ gender, $ address, $ zipcode, $ clubid, $ usertype, $ userpic, $ clothsize, $ userid, $ birthday, $ passportnu, $ gender );
If ($ res ){
Echo "script" alert ('Players ". $ realname." data modified successfully! ') Script ";
Redirect (base_url (). "team ");
}
}
}
$ ArrMember ['userid'] = $ userid;
$ ArrMember ['mobile'] = $ mobile;
$ ArrMember ['realname'] = $ realname;
$ ArrMember ['idnumber'] = $ idnumber;
$ ArrMember ['address'] = $ address;
$ ArrMember ['zipcode'] = $ zipcode;
$ ArrMember ['userpic '] = $ userpic;
$ ArrMember ['clothsize'] = $ clothsize;
// Var_dump ($ arrMember );
} Else {
// ----- Display team member information
$ StrAction = $ _ SESSION ['teamname'];
$ ArrMember = $ this-> Team_model-> getMemberInfo ($ inUserid );
$ Data ['strclothopt'] = $ this-> Common_model-> getClothOpy ($ arrMember ['clothsize']);
}
$ Data ['straction'] = "alert ";
$ Data ['arrmember'] = $ arrMember;
$ Data ['straction'] = $ strAction;
$ This-> load-> view ('head ');
$ This-> load-> view ('player', $ data );
$ This-> load-> view ('foot ');
}
------ Solution ----------------------
Modular design principle: there is an entrance and an exit. One module completes one task
Obviously, your design is not correct.
------ Solution ----------------------
$ InUserid = $ _ GET ['id'];
Do I have to determine the validity of the limit number? Very dangerous.
If ($ _ POST ['action'] = "add "){....
If ($ _ POST ['action'] = "alert "){
You just made a branch and didn't divide the function by modulo.