I am using a MVC framework, based on PHP
In my controller, I have the following functions :
public function listing($tag=null, $page=1)
{
$this->posts('`online`=1', $tag, $page, '%s/%d/');
$this->locations('`parent`=1');
}
In the same file, I have 2 functions that collect datas from 2 MySQL tables, one for the locations :
private function locations($query)
{
// Collect Locations
$locations = new Locations('WHERE '.$query.' ORDER BY `name` ASC');
$total_locations = $locations->count();
// Template
require Template::render('Posts', 'listing.html');
}
and another one for the posts :
private function posts($query, $tag, $page)
{
// Collect Posts
$posts = new Post('WHERE '.$query.' ORDER BY `date` DESC');
$total_posts = $posts->count();
$pages = ceil($total_posts/24);
if($page < 1) $page = 1;
if($page > $pages) $page = $pages;
$min = $page - 4;
$max = $page + 4;
if($min < 1)
{
$max += 1 - $min;
$min = 1;
}
if($max > $pages)
{
$min += $pages - $max;
if($min < 1) $min = 1;
$max = $pages;
}
$posts->query('LIMIT '.($page*24-24).',24');
// Template
require Template::render('Posts', 'listing.html');
}
In the public function (listing), when the first line is $this->posts... , it correctly display the Posts but doesn’t display the Locations (it just display “Array”.
If I put $this->locations... first, then it displays correctly the Loctions but not the Posts.
I don’t show you more of the code since I believe it comes from a writting mistake in my listing function
How can I display both of the arrays ?
On my view page, I display locations/posts like that :
<?php while($location = $locations->fetch($i)): ?>
<p>
<?php echo $location->title; ?>
</p>
<?php endwhile; ?>
Solved it by merging the 2
private functions togetherand just removing$this->locations('parent=1');from thepublic functionThe design was called 2 times, once with the locations and another time with the posts, since I called the template page 2 times.
The solution was simply to merge the 2 functions together !