21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 202 Views |
-
[SOLVED] Function in Controller Vs Data object

10 August 2012 at 9:06pm
I'm running through the 3.0 tutorials (http://doc.silverstripe.org/framework/en/tutorials/2-extending-a-basic-site). I'm supposed to create a function in the HomePage.php controller called LatestNews. According to the tutorial the rule of thumb is the following:
"The controller for a page is only created when page is actually visited, while the data object is available when the page is referenced in other pages, e.g. by page controls. A good rule of thumb is to put all functions specific to the page currently being viewed in the controller; only if a function needs to be used in another page should you put it in the data object."
My problem is that when I put the function in the controller it is exposed for everyone at the url http://localhost/home/LatestNews and I get an error when navigating to it. When I put it in the data object it's not exposed and I get a page not found.
I've tried with private and protected without any success. Is there anyway to not expose a controller method but still use it in the templates?
-
Re: [SOLVED] Function in Controller Vs Data object

10 August 2012 at 10:44pm
You can define the methods callable from a URL by having a static $allowed_actions array in your controller that lists them all. If you have no methods you want callable, you can use static $allowed_actions = array('index');
It appears that $allowed_actions is only mentioned in changelogs, rather than actually being documented anywhere.
-
Re: [SOLVED] Function in Controller Vs Data object

10 August 2012 at 10:48pm
Exactly what I was looking for! Thanks a lot!
| 202 Views | ||
|
Page:
1
|
Go to Top |

