salam, I'm having a problem with a variable that is undefined in view. I don't use a $data variable in the controller before. after I use the $data, it still remains doesn't appear in my view (called dashboard). Can someone help me to solve this code?
I'm sorry, I know there are questions like this before. but I want to know mine, what is the problem, besides my code in another file are fine
home.php as controller
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
$this->loginstatus->check_login();
$this->load->library('template');
$this->load->model('day_off_model');
}
public function index(){
redirect('home/info');
}
public function info(){
$data = array();
$data['ym'] = date('Y-m');
$this->template->display('information/dashboard');
date_default_timezone_set('Asia/Tokyo');
//$data['harian'] = 'a';
// Get prev & next month
if (isset($_GET['ym'])) {
$ym = $_GET['ym'];
} else {
// Bulan ini
$ym = date('Y-m');
}
//echo $ym;
// Check format
$timestamp = strtotime($ym . '-01');
if ($timestamp === false) {
$timestamp = time();
}
// Today
$today = date('Y-m-j', time());
// H3 title
$html_title = date('m Y', $timestamp);
$parts = explode(' ',$html_title);
$date = $parts[0].' '.$parts[1];
// return $date;
// print_r($html_title);
// die();
$html_title=$this->tanggal->tanggal_indo_month_yeartext($date);
// print_r($html_title);
// die();
// link prev next mktime(hour,minute,second,month,day,year)
$prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)-1, 1, date('Y', $timestamp)));
$next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)+1, 1, date('Y', $timestamp)));
// Jumlah hari seblan
$day_count = date('t', $timestamp);
// 0:Minggu 1:Senin 2:Selasa ...
$str = date('w', mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp)));
//$str = date('w', mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp))); //senin, selasa, rabu
// Create Calendar
$weeks = array();
$week = '';
// cell dengan tabel kalender
$week .= str_repeat('<td></td>', $str);
//$week .= str_repeat('<td></td>', $str-1);
for ( $day = 1; $day <= $day_count; $day++, $str++) {
$date = $ym.'-'.$day;
$exist = $this->day_off_model->get_all(false)->num_rows();
// print_r($exist);
// die();
if ($today == $date) {
$week .= '<td class="today">'.$day;
} else {
$week .= '<td>'.$day;
}
$week .= '</td>';
// End of the week OR End of the month
if ($str % 7 == 6 || $day == $day_count) {
//if ($str % 7 == 0 || $day == $day_count) {
if($day == $day_count) {
// empty cell
$week .= str_repeat('<td class="column_custom"></td>', 6 - ($str % 7));
//$week .= str_repeat('<td></td>', 7 - ($str % 7));
}
$weeks[] = '<tr>'.$week.'</tr>';
// weeks
$week = '';
}
}
//redirect('home/info');
}
dashboard.php as view
<?php if($this->session->userdata('user_type_id')==TRUE){?>
<div class="row">
<div class="col-md-12">
<h1>Sistem Informasi Absensi Kepegawaian</h1>
<hr/>
Informasi terbaru Absensi Kepegawaian<br/>
Pascasarjana Universitas Diponegoro
<?php echo validation_errors(); ?>
</div>
</div>
<div class="row">
<?php echo $ym; ?>
<div class="col-md-4">
<h3><a href="?ym=<?php echo $prev; ?>"><</a><?php echo $html_title; ?> <a href="?ym=<?php echo $next; ?>">></a></h3>
<br>
<table class="table table-bordered dashboard">
<tr>
<th class="th_custom" width="30px">Minggu</th>
<th class="th_custom" width="30px">Senin</th>
<th class="th_custom" width="30px">Selasa</th>
<th class="th_custom" width="30px">Rabu</th>
<th class="th_custom" width="30px">Kamis</th>
<th class="th_custom" width="30px">Jum'at</th>
<th class="th_custom" width="30px">Sabtu</th>
</tr>
<?php
foreach ($weeks as $week) {
echo $week;
}
?>
</table>
</div>
</div>
<?php }
else{?>
<h3>Silahkan login sebagai admin terlebih dahulu</h3>
<?php }?>
I'm curious about $ym too. variable $prev, $html_title and $next are not identified. Should I pass this code?
thank you
infomethod you need to load a view instead of redirecting. Like this:$this->load->view('home/info', $data);. You need to group up all of the data you wish to pass to the view into a single array. Also, in yourindexmethod instead of redirecting, maybe just doreturn $this->info();application/views/home/info.php. You would create a folder for your class, and a view file for each method.