Solved

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

Posted on 2014-02-16
4
341 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
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

829 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