How to get cparentID in page list's view

Permalink
Hello,

I have a page list with "beneath another page" selected. Let say the ID for the page is 10. In the page list controller, if I understand correctly, $cParentID is storing the page ID from the form. How can I send this variable to view. My intention is to get the URL of the page ID so I can assign it to the title of page list. Thanks

 
siton replied on at Permalink Reply
siton
Its hard to 100% understand what you trying to do.

** cParentID is from the DB table - so you dont need to set this variable to the view (C5 auto declare this var for you).
<?php echo $cParentID ?> //give the pageParent id

The cParentID is only integer you need to use getByID to get pageObject match to this ID.
Blog
--- post
--- post
--- post
<?php
$parentPage = Page::getByID($cParentID); // $cParentID =186 in this example
$parentName = $parentPage->getCollectionName();
echo "The parent ID is" $cParentID". "And the parent name is" .$parentName; 
// output: The parent ID is 186 And The parent name is blog
?>

----------------------------------------------------------
More methods for $parentPage. C5 docs: Getting Data about a Page:
http://documentation.concrete5.org/developers/working-with-pages/ge...

Start from Simple example ----------------------
See "hello-World" tutorial:
http://documentation.concrete5.org/developers/working-with-blocks/c...

Inside hello-World/view.php you will see:
<div><?php echo $field2 ?></div> 
// field2 is from the DB:
//<field name="field2" type="X2">

So again you dont need to "Set" $field2 var only match the names you declare from your DB table columns
----------------------------------------------------------
In GENERAL - If you want to send data from the controller to the view read her:
http://documentation.concrete5.org/developers/working-with-pages/si...

//controller.php
public function view() {
      $this->set('name', 'Cris');
}

Inside view.php
echo $name // output: Cris
vince8864 replied on at Permalink Reply
Blog
--- Category A
--- entry 1
--- entry 2
--- Category B
--- entry 1
--- entry 2

I have 2 page lists on Blog. I need each of them to have a link to Category A and Category B respectively. So in those page lists, I chose "another page" and pointed to corresponding category page. The category page ID seem to be stored as cParentID in controller and I need to retrieve it to form a link in view.


I got it working by assigning cParentID to an array and passed it through view function. However, glad to know we can access cParentID directly in view. Now, I got everything I need to make it works as intended. Thank you so much.
$parentPage = Page::getByID($cParentID);
$parentName = $parentPage->getCollectionName();
<a href="<?php echo DIR_REL . "/index.php"  . $parentPage->getCollectionPath(); ?>Link</a>
siton replied on at Permalink Reply
siton
Nice.

Can you mark "best answer" to un-list this issue from "Unanswered Only" + For future google searches. Also in the future its better to add "tags" to your Q.

thanks :) )