http://pastie.org/931617 is a link to the source code. If there is a better way to do this, let me know.
One thing I'm unsure about, is the way I handle child/parent constructs in the validation classes towards the bottom.
Thanks.
Ok, I took your advice using an associative array. Now, I just toss the $_POST variable to my construct. How does this look - http://pastie.开发者_运维问答org/931715
You handle constructs correct.
Very long lists of arguments are good in strongly typed languages such as C++, but are not very convenient and safe for PHP. My advice is to use associative arrays.
function __construct(&$args)
{
parent::__construct($args);
$this->contactphone = $this->get($args, 'contactphone'); // check if $args['contactphone'] is specified, otherwise return null
$this->firmname = $this->get($args, 'firmname');
// ...
}
Usage:
$args = array(
'username' => $username,
'password' => $password,
'confirmpassword' => $confirmpassword
);
$e = new EmployerRegister($args);
Your benefits:
You do not need to remember exact order of arguments. Create array of args in any order. Less bugs. Less typing.
Some arguments may be empty, so no need to send them. Better performance.
精彩评论