Skip to content

Commit 2b2ce58

Browse files
committed
Fixed section controller
1 parent 7652902 commit 2b2ce58

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

_config/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ContentController:
1111
extensions:
1212
- SectionContentControllerExtension
1313
url_handlers:
14-
'section/$ID!': 'handleSection'
14+
'section/$SECTIONNAME!/$ACTION!': 'handleSection'
1515
Injector:
1616
GridField:
1717
class: RowExtraClassesGridField

code/controllers/Section_Controller.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public function __contruct($section = null)
1616
$this->section = $section;
1717
$this->failover = $section;
1818
}
19-
19+
$this->CurrentPage = Controller::curr();
20+
Debug::dump($section);
2021
parent::__contruct();
2122
}
2223

@@ -39,13 +40,15 @@ public function Link($action = null)
3940
}
4041
return Controller::curr()->Link($segment);
4142
}
43+
4244
/**
43-
* @return string - link to page this section is on
45+
* Access current page scope from section templates with $CurrentPage
46+
*
47+
* @return Controller
4448
*/
45-
public function pageLink()
49+
public function getCurrentPage()
4650
{
47-
$parts = explode('/section/', $this->Link());
48-
return isset($parts[0]) ? $parts[0] : null;
51+
return Controller::curr();
4952
}
5053

5154
public function getSection()

code/extensions/SectionContentControllerExtension.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ class SectionContentControllerExtension extends Extension {
1010

1111
/**
1212
* Handles section attached to a page
13-
* Assumes URLs in the following format: <URLSegment>/section/<section-ID>.
13+
* Assumes URLs in the following format: <URLSegment>/section/<section-id>.
1414
*
1515
* @return RequestHandler
1616
*/
1717
public function handleSection() {
18-
if ($id = $this->owner->getRequest()->param('ID')) {
18+
19+
if ($ClassName = $this->owner->getRequest()->param('SECTIONNAME')) {
1920
$sections = $this->owner->data()->Sections();
20-
if ($section = $sections->find('ID', $id)) {
21-
return $section->getController();
21+
if ($section = $sections->filter(array('ClassName' => $ClassName))->first()) {
22+
if ($action = $this->owner->getRequest()->param('ACTION')) {
23+
return $section->getController()->$action();
24+
}
2225
}
2326
}
2427
// return $section->getController();

code/models/Section.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,21 @@ public function Render(){
286286
);
287287
}
288288

289+
/**
290+
* Access current page scope from section templates with $CurrentPage
291+
*
292+
* @return Controller
293+
*/
294+
public function getCurrentPage()
295+
{
296+
return Controller::curr();
297+
}
298+
289299
public function Layout()
290300
{
291301
$member = Member::currentUser();
292302
$access = Permission::checkMember($member, 'CMS_ACCESS');
293303
if($this->Public || $access){
294-
$this->CurrentPage = Controller::curr();
295304
return $this->renderWith($this->Render());
296305
}
297306
}

0 commit comments

Comments
 (0)