Jump to content

Class what is best practise? form->handler->class->db


Ansego
Go to solution Solved by trq,

Recommended Posts

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
	};
};
Link to comment
Share on other sites

  • Solution

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.