So I'm working on this project, and I'm at the point of the pagination system. Whenever a page is called, it goes the following way:
The index page searches a page, according to the $_GET variable:
if (isset($_GET['page']))
{
$tpl->parsePage($_GET['page']);
}
else
{
$tpl->parsePage('index');
}
Then the pages' name goes trough the parsePage function in my tpl class:
public function parsePage($pagename)
{
$pageid = $this->getPageIdByName($pagename);
$page = $this->shorts(new Page($pageid));
return $page;
}
It gets the pages' ID by using a function, and then creates a new page. In the page class, the pages' content is fetched from my database:
public function __construct($pageid)
{
$pageid = $pageid['id'];
$query = DB::$conn->prepare('SELECT * FROM pages WHERE id = :id LIMIT 1');
$query->bindParam(':id', $pageid, \PDO::PARAM_INT);
$query->execute();
$pageInfo = $query->fetch(\PDO::FETCH_ASSOC);
$this->pageid = $pageInfo['id'];
$this->title = $pageInfo['title'];
$this->authors = $pageInfo['authors'];
$this->contents = $pageInfo['contents'];
$this->publish_time = $pageInfo['publish_time'];
$this->edit_time = $pageInfo['edit_time'];
$this->edits = $pageInfo['edits'];
$this->editor = $pageInfo['editor'];
$this->hidden = $pageInfo['hidden'];
$this->parent = $pageInfo['parent'];
$this->category = $pageInfo['category'];
}
then the $this->contents data goes through a function which replaces all parameters with their assigned values:
private function shorts($content)
{
if(isset($_SESSION['user']))
{
$this->parameter = array_merge($this->parameter, $this->user);
}
$this->parameter = array_merge($this->parameter, $this->language, $this->system);
return $this->output = str_replace(array_keys($this->parameter), array_values($this->parameter), $content->contents); // Line 34
}
And this is where it goes wrong.. When I use this way (with $content->contents) the output is the following:
Notice: Array to string conversion in C:\xampp2\htdocs\application\classes\class.tpl.php on line 34
First thing that popped into my mind: $content['contents'], but then the output is the following:
Fatal error: Cannot use object of type C_Red\Template\Page as array in C:\xampp2\htdocs\application\classes\class.tpl.php on line 34
My knowledge stopped here...
I've marked line 34 in the shorts function. I hope that the question is clear enough to understand, but I didn't really know how to describe it, since it's a pretty vague error.
Thanks.