How do I fix the problem of routes in config.yml breaking access to Page fields?
This in my config.yml to handle routes with custom parameters (https://docs.silverstripe.org/en/3.2/developer_guides/controllers/routing/).
Director:
rules:
'mypage': 'MyPage_Controller'
When that rule is included in the config.yml it's not possible access fields and functions defined in the MyPage class via the MyPage_Controller or template. If I remove the rule from config.yml the fields and functions are accessible, but routes with many parameters don't work.
<?php
//MyPage class
class MyPage extends Page {
private static $singular_name = 'My Page';
private static $plural_name = 'My Pages';
//Not accessible if route to controller specified in config.yml
private static $db = array(
'MyPageVar' => 'Int',
);
//Not accessible if route to controller specified in config.yml
public function getMySpecialVar() {
return $this->MyPageVar;
}
}
//MyPage_Controller class
class MyPage_Controller extends Page_Controller {
private static $allowed_actions = array(
'index',
'detail',
'category',
'tag',
'search',
'detailsearch',
);
private static $url_handlers = array (
'detailsearch/$Key1/$Value1/$Key2/$Value2/$Key3/$Value3/$Key4/$Value4/$Key5/$Value5' => 'detailsearch',
);
//...
//some other code
//...
/**
* UseMyPageVar()
*
* @return Boolean
*/
public function UseMyPageVar() {
//Empty if route to controller specified in config.yml
Debug::show($this->MyPageVar);
Debug::show($this->Title);
Debug::show($this->Content);
//Error if route to controller specified in config.yml
Debug::show($this->getMySpecialVar());
return true;
}
}
Fields also are not accessible in template if route specified in config.yml
<!-- ok if no route specified, empty if route specified in config.yml -->
<p>MyVar: {$MyPageVar}</p>
<p>Title: {$Title}</p>
<p>Content: {$Content}</p>