Ansego Posted March 16, 2014 Share Posted March 16, 2014 Hello all; might be a silly question but I need to ask it, I end up with 1000+ lines of code for 10 field forms, thinking to myself this cant be right, defiantly not using the KISS principle!, so I want to try using classes and not 100% on structure or use and hoping they may make my life easier. Below is MOCK up code and my questions are: Q: Is this best practise? (form->handler->classes->db) REF BELOW CODE! Q: How do you guys handle your forms -> classes -> db? Q: What is best practise? Q: In PAGE: index.php should it be including all 3 other pages? is that how you include a class? Q: Please share rules and thumbs, hints, theories, methodologies etc etc... MOCK CODE - CODE NOT TESTED & Prob won't work just general mock for structure and logic: PAGE: INDEX.PHP (MOCK CODE) include 'inc/frm_handler.inc.inc'; include 'inc/check_class.inc'; include 'inc/dbhandler_class.inc'; <form...> <input name='test' type='text' value=''/> <input type='button' value='&Submit'/> </form> PAGE: FORM_HANDLER.INC (MOCK CODE) $testcheck = new testcheck(); $myvar = $_Post['test']; if ($testcheck.test_check($myvar) == true){ $dbsqlsend = new dbsqlexecute(); $dbsqlsend.executeSQL($myvar); } PAGE: CHECK_CLASS.INC (MOCK CODE) class testcheck{ public test_check($str_check){ if (filter_var($str_check, FILTER_SANITIZE_STRING)){ return true; } else { return false; }; }; }; PAGE: DBHANDLER_CLASS.INC (MOCK CODE) class dbsqlexecute{ public executeSQL($str_sql){ // EXECUTE MYSQLI CODE HERE ETC }; }; Quote Link to comment Share on other sites More sharing options...
Solution trq Posted March 16, 2014 Solution Share Posted March 16, 2014 Q: Is this best practise? (form->handler->classes->db) REF BELOW CODE! It is one way of handling things, and is probably pretty close to how most frameworks would handle it. Q: How do you guys handle your forms -> classes -> db? Most frameworks have some form of "form" handling built in. Q: What is best practise? Don't reinvent the wheel. Q: In PAGE: index.php should it be including all 3 other pages? is that how you include a class? No and No. Classes should be auto loaded using an autoloader (see spl_autload) Quote Link to comment Share on other sites More sharing options...
Ansego Posted March 16, 2014 Author Share Posted March 16, 2014 Thanks mate. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.