PHPに基づくMVCフレームワークを使用しています
私のコントローラーには、次の機能があります。
public function listing($tag=null, $page=1)
{
$this->posts('`online`=1', $tag, $page, '%s/%d/');
$this->locations('`parent`=1');
}
同じファイルに、2 つの MySQL テーブルからデータを収集する 2 つの関数があり、1 つは場所用です。
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');
}
public 関数 (リスト) で、最初の行が の場合$this->posts...
、投稿は正しく表示されますが、場所は表示されません (「配列」と表示されるだけです。
最初に置く$this->locations...
と、ロケーションは正しく表示されますが、投稿は正しく表示されません。
これ以上のコードはお見せしませんlisting function
両方の配列を表示するにはどうすればよいですか?
私のビューページでは、そのような場所/投稿を表示します:
<?php while($location = $locations->fetch($i)): ?>
<p>
<?php echo $location->title; ?>
</p>
<?php endwhile; ?>