views:

29

answers:

2

Hello everybody.

I have a list of buildings that I load from my model. Those buildings are showed in a loop within my view as so :

Controller

public function index() {
 $data['buildings'] = $this->Base_Model->getUserBuildings();
 $this->load->view('game', $data); }

View

<?php foreach($buildings as $b): ?>
    <div class="building">[...]</div>
<?php endforeach; ?> 

Each build has a few "actions" possible such as "info", "price", "color". the default state shows the "info".

I want to be able to load a specific action for a specific building.

For example I have a factory and a drugstore, by default both show the "info" tab. How to, if I click for the "price" tab of the drugstore, show the "info" tab for the factory AND the "price" tab for the drugstore ?

My URLs looks like these :

default one

site/buildings

show price of the drugstore

site/buildings/price/drugstore

Maybe I should look for a partial view solution but I really need an advise or a solution ;)

Thank you very much in advance (I apologize for my bad English too)

A: 

Something like this then:

$this->Base_Model->getUserBuildingFromWebname($webname);

Then in your Buildings controller you could add this:

public function index( $webname = null )
{
  if( !is_null($webname) )
    $buildingId = $this->Base_Model->getUserBuildingFromWebname($webname);
  else
    $buildingId = null;

  $data["showBuildingDetails"] = $buldingId;

  //the rest of your index() function
}

public function price ( $webname )
{
  return $this->index($webname);
}
Repox
Thank you Repox for your answer but actually I'm getting the whole list of the buildings in the index function. Then in my view I iterate through and show by default the "info". Want I want to do is to show the info but if a building is passed in the URL, then I'll show the info for the others and the price for the passed one. I achieved in a "ugly" way by doing a test in my view but I don't really like it. Any idea is appreciated, thank you again !
Magikman
A: 

without knowing more about the set up its hard to say, but you'll want some kind of conditional in your price() function

are the info/price actions obtained from the database?

if so something like

<?php foreach($buildings as $b): ?>
    <div class="building">
    <?php if($this->uri->segment(3)==$b['building_name']) {
        echo 'Price';
    } else {
        echo 'Info';
    }
    ?>    
    </div>
<?php endforeach; ?> 

but as stated without knowing more about the system it is hard to give a decent answer.

Ross