Что мне нужно сделать, так это использовать массив переменных top5 для моей индексной страницы.На данный момент он говорит, что это неопределенная переменная.Таким образом, с помощью оператора if, который назначает переменную страницы, которую он должен знать, чтобы отправить массив переменных top5 вместе с ним, если его страница индекса будет загружена.Когда я выполняю print_r переменной top5 в контроллере, она выглядит так:
Array ( [0] => Array ( [character_name] => Kid Wonder ) [1] => Array ( [character_name] => Ryu Satoshi ) [2] => Array ( [character_name] => Oriel ) [3] => Array ( [character_name] => "The Ladies Man" Luscious Landon ) [4] => Array ( [character_name] => "The Outlaw" Mike Mayhem ) )
Контроллер:
$siteInfo = $this->site->getSiteTitleAndSlogan();
$activeTemplate = $this->site->getTemplate();
if ($this->site->pageStatus('index', $activeTemplate[0]->id) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index', '', true);
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404', '', true);
}
$footerLinks = $this->site->getFooterNav();
$top5 = $this->site->getTop5();
print_r($top5);
$this->template
->title($siteInfo[0]->site_name,$siteInfo[0]->site_slogan)
->prepend_metadata('<link rel="stylesheet" type="text/css" href="http://www.kansasoutlawwrestling.com/assets/css/'.$activeTemplate[0]->short_name.'.css" />')
->set('footerLinks', $footerLinks)
->set('page', $page)
->set('top5', $top5)
->set_partial('header', $activeTemplate[0]->short_name.'/header')
->set_partial('navigation', $activeTemplate[0]->short_name.'/navigation')
->set_partial('content', $activeTemplate[0]->short_name.'/content')
->set_partial('footer', $activeTemplate[0]->short_name.'/footer')
->build('kow');
РЕДАКТИРОВАТЬ:
Вот моя система шаблонов.
/views
/views/kow.php (template file)
/views/v1 (current template version)/
/views/v1/header.php
/views/v1/footer.php
/views/v1/navigation.php
/views/v1/content.php
/views/v1/pages/
/views/v1/pages/index.php(homepage)
/views/v1/pages/404.php(error page)
Просмотр содержимого:
<div id="content">
<?php
echo $page;
?>
</div>
Просмотр индексной страницы:
<div id="left">
<div id="spotlight">
<img id="spotlight" src="assets/images/spotlight.png" alt="Kansas Outlaw Wrestling" />
</div>
<div id="top5">
<ol>
<?php
for ($i = 0; $i >= count($top5); $i++){
foreach($top5[$i] as $row)
{
$seperator = ($elements == $count) ? '' : '<hr />';
$name = (!isset($row['character_name'])) ? 'TBD' : $row['character_name'];
$count++;
?>
<li><span class="red"><?php echo $name; ?></span></li>
<?php
}
}
?>
</ol>
</div>
</div>
<div id="middle">
<div id="topnews">
<img id="topnewspic" src="assets/images/kelly.png" alt="Top News Pic" valign="right" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sit amet mauris et erat luctus faucibus. In hac habitasse platea dictumst. Nunc sollicitudin ultricies nisi vel blandit. Quisque tincidunt mattis lacinia. Maecenas porttitor magna eu velit hendrerit ornare. Donec ultrices porttitor tellus sed venenatis. Integer ipsum lacus, malesuada eget ornare vel, mollis vel metus. Fusce a orci sed dui accumsan luctus et id enim. Aenean ac dui orci. Nam fringilla rutrum libero eget laoreet. Mauris ac sem metus, a ultrices ante. Duis quam metus, rhoncus sed dictum vel, ultricies vel nibh. Pellentesque enim lorem, mollis ut lacinia ac, aliquet id magna. Proin ante sapien, molestie in tincidunt hendrerit, blandit ut dolor. In rhoncus convallis ullamcorper. Integer sed arcu vitae libero dapibus interdum.</p>
<p>Sed nibh leo, consequat non tempor vitae, fringilla eget augue. Pellentesque libero turpis, lobortis euismod consectetur eu, ultrices non orci. Aliquam erat volutpat. Sed et nunc orci. Aliquam semper tortor in nunc placerat pulvinar. Etiam placerat ornare metus, id malesuada mi venenatis quis. Suspendisse dapibus, metus sollicitudin dictum aliquet, nisi dui tempus felis, a tristique sem est at ligula. Praesent commodo dolor ac ante ornare id cursus tellus luctus. Vivamus pretium metus ut dui hendrerit tincidunt.</p>
</div>
</div>
<div id="right">
<div id="upcomingevents">
<ul>
<li>Warpath<span class="red">October 31, 2011</span></li>
<hr />
<li>Warpath<span class="red">October 31, 2011</span></li>
<hr />
<li>Warpath<span class="red">October 31, 2011</span></li>
<hr />
<li>Warpath<span class="red">October 31, 2011</span></li>
<hr />
<li>Warpath<span class="red">October 31, 2011</span></li>
</ul>
</div>
<div id="poll">
<p id="question" class="red">How is it coming along?</p>
</div>
</div>
РЕДАКТИРОВАНИЕ 2:
Контроллер:
$siteInfo = $this->site->getSiteTitleAndSlogan();
$activeTemplate = $this->site->getTemplate();
if ($this->site->pageStatus('index', $activeTemplate[0]->id) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index', '', true);
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404', '', true);
}
$footerLinks = $this->site->getFooterNav();
$toprankings = $this->site->getTop5();
//$top5 = Array ( Array ( "character_name" => "Kid Wonder" ), Array ( "character_name" => "Ryu Satoshi" ), Array ( "character_name" => "Oriel" ), Array ( "character_name" => "\"The Ladies Man\" Luscious Landon" ), Array ( "character_name" => "\"The Outlaw\" Mike Mayhem" ));
$data['$toprankings']=$toprankings;
$this->template
->title($siteInfo[0]->site_name,$siteInfo[0]->site_slogan)
->prepend_metadata('<link rel="stylesheet" type="text/css" href="http://www.kansasoutlawwrestling.com/assets/css/'.$activeTemplate[0]->short_name.'.css" />')
->set('footerLinks', $footerLinks)
->set('page', $page)
->set('toprankings', $toprankings)
->set_partial('header', $activeTemplate[0]->short_name.'/header')
->set_partial('navigation', $activeTemplate[0]->short_name.'/navigation')
->set_partial('content', $activeTemplate[0]->short_name.'/content', $data)
->set_partial('footer', $activeTemplate[0]->short_name.'/footer')
->build('kow');
Вид:
<?php
for($i=0;$i < count($toprankings); $i++)
{
echo "character_name: ".$toprankings[$i]['character_name']."<br>";
}
?>