Solved

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

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now