Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Page extends SiteTree {
- private static $allowed_children = array ('*Page'); // Only Base Class Pages can be created as children.
- private static $db = array(
- );
- private static $has_one = array(
- );
- }
- class Page_Controller extends ContentController {
- /**
- * An array of actions that can be accessed via a request. Each array element should be an action name, and the
- * permissions or conditions required to allow the user to access it.
- *
- * <code>
- * array (
- * 'action', // anyone can access this action
- * 'action' => true, // same as above
- * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
- * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
- * );
- * </code>
- *
- * @var array
- */
- private static $allowed_actions = array (
- );
- public function __construct(){
- echo __FILE__ . " on line " . __LINE__ . "<br>";
- parent::__construct();
- }
- public function init() {
- parent::init();
- // You can include any CSS or JS required by your project here.
- // See: http://doc.silverstripe.org/framework/en/reference/requirements
- }
- public function getPagesWithDepth(){
- echo __FILE__ . " on line " . __LINE__ . "<br>";
- $pageList = new ArrayList();
- foreach( SiteTree::get() as $menuPage){
- $pageList->push( ArrayData::create([
- 'title' => $menuPage->getTitle(),
- 'id' => $menuPage->ID,
- 'depth' => $this->getHDepth($menuPage),
- 'parentId' => ($menuPage->getParent())? $menuPage->getParent()->ID : 0
- ]));
- }
- return $pageList;
- }
- public function getHDepth( Page $menuPage){
- if($menuPage->getParent()){
- return $this->getHDepth($menuPage->getParent()) +1;
- }
- return 0; // stopping case
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement