Manchmal brauche ich Daten wie Array und manchmal brauche ich dieselben Daten wie JSON.OOP MVC - Modell oder Controller zur Überprüfung des Rückgabedatentyps?
Wo würdest du prüfen, ob es einen Ajax-Anruf gibt, in Controller oder Modell oder ... Welches ist besser?
-Test ist, wenn Anruf ajax in Controller
function my_controller(){
//getdata from model
$data=$this->my_model();
if(THIS_IS_AJAX_CALL){
echo json_encode($data);
}else{
return $data;
}
}
function my_model(){
//get the data from db
return $data;
}
Pass-Typ als Argument Modell:
function my_controller(){
if(THIS_IS_AJAX_CALL){
return $this->my_model('json');
}else{
return $this->my_model();
}
}
function my_model($type=''){
//get the data from db
if($type='json'){
return json_encode($data);
}else{
return $data;
}
}
Danke Maerlyn :) – mojeime