Welcome Guest, Not a member yet? Register   Sign In
Calendaring class
#1

[eluser]Drinian[/eluser]
Hi,

I've been trying to use the Calendaring class. The documentation seems to have an error in it regarding "Showing Next/Previous Month Links". It has you passing the prefs in the generate method, and I think it should be when you load the class.

However, even accounting for that, I can't get the next/previous links to work. They form properly but when you click on them I get a 404 page. Any advice? Thanks in advance.

Here's the code:

class Cal extends Controller {

function index() {

$prefs = array ('start_day' => 'saturday',
'month_type' => 'long',
'day_type' => 'short',
'show_next_prev' => TRUE,
'next_prev_url' => 'http://www.mydomain.com/index.php/cal/'
);


$this->load->library('calendar', $prefs);

echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));

}

}
#2

[eluser]sophistry[/eluser]
I believe that you need to hard code 'index' as the function name in your next_prev_url pref.
#3

[eluser]Drinian[/eluser]
Yes, that is it. Thanks.
#4

[eluser]sophistry[/eluser]
Yeah, I thought I remembered something weird like that. The calendar class is full of quirks like that which make it not the most (ahem) robust class for substantial development.
#5

[eluser]ericsodt[/eluser]
I can not even get the links to show up given the code in the API. Does anyone know how to fix this problem?
#6

[eluser]Drinian[/eluser]
Check if you initialized the class in your controller:
Code:
$this->load->library('calendar');
If you want to set preferences they must be passed during the load, not during the 'generate' function (like the docs say in one place):
Code:
$prefs = array (
               'start_day'    => 'saturday',
               'month_type'   => 'long',
               'day_type'     => 'short'
             );

$this->load->library('calendar', $prefs);
Then to see the calendar you echo the generate function:
Code:
echo $this->calendar->generate();
To show the next/prev links you set the prefs for that:
Code:
$prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   => 'http://www.your-site.com/index.php/calendar/show/'
             );
$this->load->library('calendar', $prefs);
echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));
The above code has 'show' as the function in the controller. My problem was that I thought if I used 'index' I wouldn't have to explicitly list that in the next_prev_url but you do have to put it.

Hope that helps.
#7

[eluser]Sumon[/eluser]
I am very sorry to say Calendar class of CI is not good enough. Not well configurable. Let me share some informations with you. According to CI user guide i found that the following code will able to display next/prev button
Code:
$prefs = array (
               'show_next_prev'  => TRUE,
               'next_prev_url'   => 'http://www.your-site.com/index.php/calendar/show/'
             );
$this->load->library('calendar', $prefs);
echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));
But i am surprised and waste a lot of my times with my believe. Finally i got that this code is not configurable. If anyone like to configure then he/she have to Edit the main Calendar class inside CI_Root/system/libraries. Isn't it looks funny? I need to configure inside a built in class!!
Still i am facing another problem. This time next/previous link add an extra segment. What is it !!!!
#8

[eluser]RaiNnTeaRs[/eluser]
hmm my calendar function works fine,I dont have to edit the calendar library. the $this->uri->segment code is made so you can choose what month and years to display in your calendar.




Theme © iAndrew 2016 - Forum software by © MyBB