Welcome Guest, Not a member yet? Register   Sign In
Adding multiple variables to calendar days

There are two ways to solve this.

1. Put your css styles in a 2-dimensional array (in the controller):
PHP Code:
$css = array(
 1 => array(
   3 => 'cal-blue',
   7 => 'cal-red'
 5 => array(
   4 => 'cal-red',
   23 => 'cal-green'
In this exemple, you create styles for a few days in January and May.
Pass this array to the view.

You also need to change the MY_Calender class.
Insert this at the beginning of the generate() function:
PHP Code:
$m $month //because you change $month to a 2-character string; later on you need $m as a digit 

Then, at the position where you inserted new code, change the line that starts with $csstmp:
PHP Code:
$csstmp = isset($css[$m][$day]) ? 'class="' $css[$m][$day] . '"' NULL

2. Generate all months from the controller (in a loop).
The generate() function returns a string.
Put all 12 strings in an array and pass it to your view.
PHP Code:
for ($month 1$month <= 12$month++) {
  //collect $data from other function in controller or model
  //collect $css from other function in controller or model
  $cal_months[] = $this->calendar->generate($year$month$data$css);
$this->data['cal_months'] = $cal_months;
This way, you can leave the MY_Calendar class as it is now. But you will have to rewrite the view.
With this approach, you move more of your application's logic to the controller, which is better. Keep your views as simple as possible.

In your current view, the $css array is initialized several times (line 10 and line 31). This means that the $css array that you passed from the controller, gets overwritten. Comment these 2 lines with // and see what that does.

With this, you must be able to work it out by yourself. I'm reluctant to write the complete application for you. You learn CI best by overcoming your own mistakes. Good luck!

Messages In This Thread
RE: Adding multiple variables to calendar days - by Wouter60 - 08-08-2017, 01:07 PM

Theme © iAndrew 2016 - Forum software by © MyBB