Solved

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

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…

776 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