What is the $c variable for?

Permalink
I notice the $c variable is used often. Is it the same variable globally? What exactly does the $c variable point to / do ???

ob7dev
 
A3020 replied on at Permalink Best Answer Reply
A3020
It stands for "current page" and it contains a Page object.

You can do stuff like:
echo $c->getCollectionName();
echo $c->getAttribute('some_attribute');


It is not available in *every* php file. If the object is not available, you can retrieve it with:
$c = Page::getCurrentPage();
siton replied on at Permalink Reply
siton
Some code to more understand the $c:
Example-1: If current page is in edit mode:
if ($c->isEditMode()) {
echo 'You are editing this page';
}

Example-2: prints area to the object $c:
$areaSidebar = new Area('Sidebar');
$areaSidebar->display($c);

Also its very handy to understand what is this "->" arrow and some OOP basics:
"he use of the arrow (->) is an OOP construct that accesses the contained properties and methods of a given object."
See the full tutorial her:
http://code.tutsplus.com/tutorials/object-oriented-php-for-beginner...
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi ob7dev,

I recommend reviewing the documentation on pages.
http://documentation.concrete5.org/developers/working-with-pages/ov...