Solved

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

Posted on 2014-02-16
4
349 Views
Last Modified: 2014-02-17
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
Comment
Question by:johnecollins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Accepted Solution

by:
HagayMandel earned 167 total points
ID: 39864038
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
 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 166 total points
ID: 39864057
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
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 167 total points
ID: 39864480
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
 

Author Closing Comment

by:johnecollins
ID: 39866590
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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to count occurrences of each item in an array.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question