我使用的MVC框架,基于PHP控制器功能在PHP
在我的控制,我有以下功能:
public function listing($tag=null, $page=1)
{
$this->posts('`online`=1', $tag, $page, '%s/%d/');
$this->locations('`parent`=1');
}
在同一文件中,我有2个功能收集从2个MySQL表,一个是位置DATAS:
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');
}
,另一个用于帖子:
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');
}
在公共函数(列表)中,当第一行是$this->posts...
时,它正确显示帖子但不显示位置(它只显示“Array”。
如果我先放$this->locations...
,那么它会正确显示Loctions而不是Posts。
我没有你更多的代码显示,因为我相信它来自一个书面方式错误在我listing function
我怎样才能既显示阵列?
在我的视图页面,我展示位置/职位这样的:
<?php while($location = $locations->fetch($i)): ?>
<p>
<?php echo $location->title; ?>
</p>
<?php endwhile; ?>
很好的捕获,但实际上第一个参数是文件夹'my_path/Posts/listing.html'的名称 所以它们都是相同的,因为我想要2个数组显示在同一页上 – PhilMarc
可以包含源代码这个文件的。 – Gustek
除了<?php 类广告延伸控制器 {'在开头 – PhilMarc