开发者

Query string and next/previous in calendaring class

开发者 https://www.devze.com 2023-02-09 18:45 出处:网络
How can I show the next/previous links in the calender when using query strings? http://codeigniter.com/user_guide/libraries/calendar.html

How can I show the next/previous links in the calender when using query strings?

http://codeigniter.com/user_guide/libraries/calendar.html

开发者_开发问答

Thanks.


This should be fairly straightforward, but it's not as easy as setting an option.

Firstly, make sure you set your preferences so that the "show_next_prev" is set to true and set the "next_prev_url" to whatever URL you have your calendar at. Make sure you don't put anything at the end of the URL eg a slash or question mark etc.

Secondly, so as not to hack a core library file create a new class called MY_Calendar and place it in your application/library folder. Make this class extend the Calendar class.

Next copy and paste the generate() function from the original Calendar class into your new MY_Calendar class. We can now edit this function and it will overwrite without removing the original.

Find the line (around line 163) where it a trailing slash is added the the next_prev_url variable and delete it.

A few lines further on you will see:

$out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_previous_cell']);

Replace this line with:

$out .= str_replace('{previous_url}', $this->next_prev_url.'?year='.$adjusted_date['year'].'?month='.$adjusted_date['month'], $this->temp['heading_previous_cell']);

Then do exactly the same a few lines later for the next_url. It should be around line 183 and will look very similar.

And that should be it. All you've done is made sure the syntax that is generated for the next and prev urls matches the query string style.

Please note, I haven't tested this, but it should work!

0

精彩评论

暂无评论...
验证码 换一张
取 消