[eluser]Unknown[/eluser]
Hello. I have been using CI for a few months and I am on my first major site build. My problem is as follows.
The site I am building is a product catalog. I have a menu which I coded into a view called menu.php, which is then loaded into other view pages as needed. The links in this menu have the following structure:
Code:
"index.php/costumes/animal"
My intent was to pass the variable "animal" to a function in my costumes.php controller. In reading the user guide, I thought I could accomplish this via the routes.php file. I did this so that I can have an informative URL in the address bar, instead of the default function/controller/variable URL.
I have set up a route in routes.php:
Code:
$route['costumes/(:any)'] = "costumes/product_lookup/$1";
.
All was working fine. The intended variable "animal" was being passed through to the product_lookup function of my costumes controller; however when the subsequent view is loaded and I include the menu.php view, the menu links become additive. Now if I click the same the link it returns
Code:
index.php/costumes/animal/index.php/costumes/animal
. Each click which follows on subsequent view loads continues this, rendering my links useless. I have included my code below. Any help/insight would be greatly appreciated.
Example Menu Link:
Code:
<li class="subC"><a href="index.php/costumes/animal">Animal</a></li>
Route:
Code:
[code]$route['costumes/(:any)'] = "costumes/product_lookup/$1";[/code]
Home View:
Code:
<?php $this->load->view('header');?>
<div id="mainContent">
<div id="rightCol">
<img src="<?=base_url()?>assets/img/edhardyIntimates_logo.jpg" class="ad" />
</div>
<div id="home">
<img src="<?=base_url()?>assets/img/costumes.png" id="mainAd" />
</div>
<?php $this->load->view('menu');?>
</div><!--End of maincontainer-->
<br class="clearfloat" />
<?php $this->load->view('footer');?>
Costumes Controller:
Code:
<?php
class Costumes extends Controller {
function Costumes()
{
parent::Controller();
$this->load->model('Content');
$subcat = $this->uri->rsegment(3);
}
function index()
{
}
function product_lookup($subcat)
{
$category = $this->uri->rsegment(1);
$data['query'] = $this->Content->product_by_subcat($category, $subcat);
$data['category'] = $category;
$data['subcat'] = $subcat;
$this->load->view('product', $data);
}
}
Product View:
Code:
<?php $this->load->view('header');?>
<div id="mainContent">
<div id="display">
<h3>Product Title</h3>
<img src="img/detail.jpg" class="detail" alt="detail image" />
<img src="img/detail.jpg" class="detail" alt="detail image" />
<p>
Some Costume item # 123456
</p>
</div><!--End of display-->
<div id="thumbnails">
<h2><?=$category?> » <?=$subcat?></h2>
<span class="pagination">< 1 2 3 ></span>
<?php foreach($query as $row) :?>
<img >thumb?>" class="thumb" alt="thumbnail"/>
<?php endforeach?>
<span class="pagination">< 1 2 3 ></span>
</div><!--End of thumbnails-->
<?php $this->load->view('menu');?>
</div><!--End of maincontainer-->
<br class="clearfloat" />
<?php $this->load->view('footer');?>
Again the menu link works fine when fired from the home view, but the url string duplicates itself on all subsequent view loads.
Thanks in advance for any help on this matter.