It happens that I am showing some data from my Database through some Foreach, in which I am using echo to show the value of each field that I require. So far I have used in my query sql, in the WHERE condition any value that throws a result to show it, however this must do it by means of some variable, in this case it would be $ rut_usu, which will store the selected rout from a select (listboxt) in the view. But when adding in the model, in the sql query my variable (which does not yet have any value, because I have not selected any value from the listboxt) throws me the following error:
An uncaught Exception was encountered
Type: ArgumentCountError
Message: Too few arguments to function M_Calendar::monday(), 0 passed in C:\xampp\htdocs\SAE\application\controllers\C_Calendar.php on line 23 and exactly 1 expected
Filename: C:\xampp\htdocs\SAE\application\models\M_Calendar.php
Line Number: 106
Backtrace:
File: C:\xampp\htdocs\SAE\application\controllers\C_Calendar.php
Line: 23
Function: monday
File: C:\xampp\htdocs\SAE\index.php
Line: 315
Function: require_once
What would be the solution to this, should I do what I require in some other way?
I leave my code:
Controller:
public function index(){
$this->load->view('layouts/Header.php');
$this->load->view('layouts/Menu.php');
$this->load->model('M_Calendar');
$data['monday'] = $this->M_Calendar->monday();
$data['tuesday'] = $this->M_Calendar->tuesday();
$data['Wednesday'] = $this->M_Calendar->wednesday();
$data['thursday'] = $this->M_Calendar->thursday();
$data['friday'] = $this->M_Calendar->friday();
$data['saturday'] = $this->M_Calendar->saturday();
$data['usuarios'] = $this->M_Calendar->get_usuarios();
$this->load->view('usuarios/V_Consulta_Horarios.php',$data);
$this->load->view('layouts/Footer.php');
}
Model (I have several functions like this, from Monday to Saturday)
public function monday($rut_usu){
$this->db->select('MIN(horario.hrs_ini) AS hrs_ini, MAX(horario.hrs_ter) AS hrs_ter ');
$this->db->from('horario');
$this->db->join('usuarios','horario.rut_usu = usuarios.rut_usu');
$this->db->where('usuarios.rut_usu',$rut_usu);
$this->db->where('horario.lunes','ATTE. ESTUDIANTES');
$this->db->where('fecha_registro = (SELECT MAX(fecha_registro) FROM horario)');
$this->db->limit('14');
$monday = $this->db->get();
if($monday->num_rows() > 0 ){
return $monday->result();
}
}
I'm showing the variables inside a javascript using fullcalendar, which as I mentioned before worked fine
businessHours: [ // specify an array instea
{
dow: [ 1], // Monday
<?php foreach($monday as $row){?>
start: '<?php $inicio= "00:00"; $start1_ok = $row->hrs_ini;
if (empty($start1_ok)) { echo $inicio;}
else { echo $start1_ok;} ?>', // empty evalúa si el campo se encuentra vació o si es cero
end: '<?php echo $row->hrs_ter ;?>'
<?php }?>
},