[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

Controller call to View does not bring the parameters that are part of the Call

I have created a CodeIgniter MVC

The Controller loads the model in the constructor.

In the Index function there is a call to the model to get the details of two arrays needed to service two dropdown fields setting up a search based on the dropdown fields to focus on a selection of lower level entities

The calls to the model work fine and return the arrays I am expecting I have used var_dump to establish this.

When I call the view
" $this->load->view("Archery/header", $seasons, $leagues, $title);"

the header is rendered
but the $seasons, $leagues and $title variables are not visible in the view.

Can anybody recommend a way of passing the missing data?

Thank you

John
0
johnecollins
Asked:
johnecollins
3 Solutions
 
HagayMandelCommented:
It's been quite long a time since I've been playing with CI, but I'll try:
If I remember correctly, the call for loading the view includes one array of variables only.
$this->load->view('content', $data);

Open in new window

You should include your variables in the $sata array prior to the call itself:
$data('var_name') = 'SOME VALUE';

Open in new window

the var_name itself can be an array, so that $data will be a multi dimensional array.
CI knows to extract the variables once the view is loaded, so $var_name will be available to the view.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
Check out this link, http://ellislab.com/codeigniter/user-guide/general/views.html 

The above link shows clear instruction to pass the variable from controller to view.
0
 
Chris StanyonCommented:
You pass the data as an array and the array keys are turned into variable in the view, so you would need something like this:

$data = array(
   'seasons' => $seasons,
   'leagues' => $leagues,
   'title' => $title
);

$this->load->view('Archery/header', $data);

Open in new window

0
 
johnecollinsAuthor Commented:
Hagay, thank you for your recollections

Loganathan thank you for the link

Chris good to hear from you thanks for the information

I have graded the answers with regard to the amount I learnt

So thank you all very much for your help

Thanks

John
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now