Welcome Guest, Not a member yet? Register   Sign In
Calendar class not working
#1

[eluser]eboxhead[/eluser]
So I'm brand spanking new to CI, and I've been playing with the calendar class. I can display the calendar just fine, do most of the prefs no issues, but as soon as I try to use the next / prev pref the thing falls apart. The initial calendar loads fine, but as soon as I try to change the month i get a 404 error.

I'm using CI 1.7.2 and MAMP. the URL for calendar is http://localhost:8888/ci/index.php/test/

My controller page looks like this:
Code:
<?php

    class Test extends Controller {
        function index()
        {
            
            
            $prefs = array (
                           'show_next_prev'  => TRUE,
                           'next_prev_url'   => 'http://localhost:8888/CI/index.php/test/'
                         );

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

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

I've copied the code straight from the user guide and adjusted the params as needed.

Any suggestions? What am I missing?
#2

[eluser]maria clara[/eluser]
you've missed the brackets in your $prefs

Code:
<?php

    class Test extends Controller {
        function index()
        {
            
            
            $prefs[]= array (
                           'show_next_prev'  => TRUE,
                           'next_prev_url'   => 'http://localhost:8888/CI/index.php/test/'
                         );

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

            echo $this->calendar->generate($this->uri->segment(2), $this->uri->segment(3));
        }
    }
#3

[eluser]eboxhead[/eluser]
Thanks, just tried that. When I do that the next / prev links dissapear.
#4

[eluser]helmutbjorg[/eluser]
Your prefs were fine... remove those brackets. What is the address that is at the top when you get the 404?
#5

[eluser]eboxhead[/eluser]
http://localhost:8888/CI/index.php/test/2010/03
#6

[eluser]helmutbjorg[/eluser]
Does http://localhost:8888/CI/index.php/test work when you put that in the address bar and hit enter?
#7

[eluser]danmontgomery[/eluser]
I don't use the calendar class, but it seems to me that CI would be trying to route test/2010/03, maybe you should set up routes for the calendar?
#8

[eluser]helmutbjorg[/eluser]
Try setting your next_prev_url to this...
Code:
'next_prev_url'   => 'http://localhost:8888/CI/index.php/test/index/'
#9

[eluser]eboxhead[/eluser]
Thanks, chanign the next_prev_url worked after i changed the URI segments. is that because i have an index function in the controller? is that required?
#10

[eluser]helmutbjorg[/eluser]
The index function is required. I think the example in the user guide assumes you are making a new function rather than putting that code in the index. You could take that code out of the index and put it in a new method called test/calendar or someting like that.

If you don't want to put that code in a function other than index you can hide the index bit with a route.

Eg.

Code:
$route['test/(:num)/(:num)'] = 'test/index/$1/$2';




Theme © iAndrew 2016 - Forum software by © MyBB