My apologies if this is already explained somewhere, but I have tried to find the solution but to no avail.
I am trying to extend the URL params that are allowed for a particular controller on a new site I am building
http://domainname.local/my-zone/body/calendar/10/2011/
http://domainname.local/pagename/$Action/$ID/$OtherID/?/
This leaves me one parameter short and rather than just use a ?year=2011 I wanted to learn how to add another parameter to the URL.
In this set up my-zone is a page and so is body.
Body has a pagetype of WeighIn and calendar is a method on the WeighIn_Controller
I have tried adding the Rule to Director in a number of different ways but no luck, so I guess my understanding of it is completely wrong. Would appreciate any help.
Cheers,
Colin
/mysite/_config.php
Director::addRules(100, array('/my-zone//$Action/$ID/$OtherID/$Year'=>'WeighIn_Controller'));
/mysite/WeighIn.php
<?php
class WeighIn extends Page {
public static $db = array(
);
public static $has_one = array(
);
static $icon = "/themes/dd/images/treeicons/user_orange";
}
class WeighIn_Controller extends Page_Controller {
public static $allowed_actions = array (
'entry',
'addentry',
'saveentry',
'calendar',
'list'
);
public function init() {
parent::init();
}
/***************************************
* Add Weigh In Point
*/
function addentry() {
// form code
}
function saveentry($data, $form) {
// Save code
}
/* draws a calendar */
function draw_calendar($month,$year){
// code to draw calendar
}
function CalendarHTML($month = null, $year = null) {
echo "Year = ".Director::urlParam('Year')."<hr/>";
echo "Action = ".Director::urlParam('Action')."<hr/>";
echo "ID = ".Director::urlParam('ID')."<hr/>";
echo "OtherID = ".Director::urlParam('OtherID')."<hr/>";
if($month === null){
$month = date("n");
}
if($year === null){
$year = date("Y");
}
return $this->draw_calendar($month, $year);
}
}