2
How to do the if
controller return TRUE
or FALSE
in accordance with the check()
of the Validator?
Currently it returns boolean to the validate();
, but I wanted it to continue until the end of the code, to then return the boolean.
<?php
# relatorio venda controller
class RelatorioVendaController {
public function __construct() {
$form['nome'] = 'Ricardo';
$form['idade'] = 24;
if(RelatorioVenda::validate($form)){
print 'Nenhum erro.';
}
}
}
# relatorio venda model
class RelatorioVendaModel extends RelatorioModel {
public static function validate($form){
$validators = array(
"nome" => "required",
"idade" => "required"
);
parent::rules($form, $validators);
}
}
# relatorio model
class RelatorioModel {
public static function rules($form, $validators){
// junta os arrays foreach e executa a validacao
Validator::check($field, $map['field'], $map['validator']);
}
}
class Validator {
public static function check($field, $value, $validator){
// execute validator(field, value)
if(no erros)
return true;
}
public function required($field, $value){
// validator
}
}
?>
check your check function, there is a syntax error in
if(no erros)
Edited: the functionrules
of the Report Model class needs areturn
also– gmsantos
I think the right thing would be
if(no errors)
– Silvio Andorinha
is just marking, this class is conceptual.
– Ricardo
Can you clarify further what you want the code to do? I did not understand the part of going to the end of the code. Another thing, "object orientation" means not only having classes and inheritance but also encapsulation, which is lost with how many static functions (Static). This is practically like creating global functions. You should re-organize the code to get rid of static functions if possible.
– Jonas Hartmann
Where does that come from
$form
in the Controller constructor? The.o– Henrique Barcelos
@Henriquebarcelos From anywhere, it can be a form, as here is just an example is implicit in the code.
– Ricardo
@Jonashartmann When I call the Reportproposal::validate(), it performs this function and returns boleanus according to that scope. I would like it to follow "Parent::Rules($form, $validators)" and depending on the result there, it returns there in the controller. It gets a little confusing to explain, but you’ve managed to understand?
– Ricardo