What I need to happen is have the top5 variable array get used for my index page. As of right now it says its an undefined variable. So with the if statement that assigns the page variable it needs to know to send the top5 variable array with it IF its the index page its going to load. When I do a print_r of the top5 variable in the controller it shows up like this:
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 ) )
Controller:
$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');
EDIT :
Here’s my template system.
/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)
Content View:
<div id="content">
<?php
echo $page;
?>
</div>
Index Page View:
<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>
EDIT 2 :
Controller:
$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');
View:
<?php
for($i=0;$i < count($toprankings); $i++)
{
echo "character_name: ".$toprankings[$i]['character_name']."<br>";
}
?>
Your
forloop is backwards.should be
$istarts at0and therefore will never be more thancountand even if it is equal will never increment nor iterate.Try deleting everything in your view except the top5 part, and change that to:
just to see if it’s working. Also, it’d help to know what templating system you are using.