Reputation: 171
P.S I'm a newbie in codeigniter and searched for answers but its far beyond my comprehension so I will ask this question for my level.
I just found this code for a dynamic breadcrumb helper in youtube and I am receiving an error. Can you guys help me debug it? Cause I'm confuse with his code but its an efficient one cause you just simply echo the function in VIEW. This is the error:
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected ';'
Filename: helpers/breadcrumb_helper.php
Line Number: 15
Backtrace:
Here is the code
<?php
if(!function_exists('generatedBreadcrumb')){
function generateBreadcrumb(){
$ci=&get_instance();
$i=1;
$iro = $ci->iri->segment($i);
$link='
<div class="pageheader">
<h2><i class="fa fa-edit"></i>'.$ci->uri->segment($i).'</h2>
<div class="breadcrumb-wrapper">
<ol class="breadcrumb">';
while($uri != "){
$prep_link = ";
$for($j=1; $j<=$i; $j++){
$prep_link.=$ci->uri->segment($j).'/';
}
if($ci->uri->segment($i+1)=="){
$link.='<li class="active"><a href=".site_uri($prep_link).">';
$link.=$ci->uri->segment($i).'</a></li>';
}else{
$link.='<li><a href=."site_url($prep_link).">';
$link.=$ci->uri->segment($i).'</a><span class="divider"></span></li>';
}
$i++;
$uri = $ci->uri->segment($i);
}
$link .='</ol></div></div>';
return $link;
}
}
Upvotes: 2
Views: 4274
Reputation: 675
Getting error of
Fatal error: Call to a member function segment() on null in breadcrumb_helper.php
You have also changed the following, like this:
$iro = $ci->iri->segment($i);
should be:
$uri = $ci->uri->segment($i);
And so on.
Upvotes: 0
Reputation: 2871
You set the $variables
with one double quote not two, like this:
while($uri != "){}
should be:
while($uri != ''){}
And also this:
$prep_link = ";
should be:
$prep_link = '';
And so on.
Upvotes: 1
Reputation: 19
if(!function_exists('generatedBreadcrumb')){
function generateBreadcrumb(){
$ci=&get_instance();
$i=1;
$uri = $ci->uri->segment($i);
$link='
<div class="pageheader">
<h2><i class="fa fa-edit"></i>'.$ci->uri->segment($i).'</h2>
<div class="breadcrumb-wrapper">
<ol class="breadcrumb">';
while($uri != ''){
$prep_link = '';
for($j=1; $j<=$i; $j++){
$prep_link.=$ci->uri->segment($j).'/';
}
if($ci->uri->segment($i+1)== ''){
$link.='<li class="active"><a href="'.site_url($prep_link).'">';
$link.=$ci->uri->segment($i).'</a></li>';
}else{
$link.='<li><a href="'.site_url($prep_link).'">';
$link.=$ci->uri->segment($i).'</a><span class="divider"></span></li>';
}
$i++;
$uri = $ci->uri->segment($i);
}
$link .='</ol></div></div>';
return $link;
}
}
Upvotes: 1