Welcome Guest, Not a member yet? Register   Sign In
New to CI
#1

[eluser]nathanashton[/eluser]
Hi All,

Ive recently been learning PHP and have been introduced to Codeigniter. I've been through some code of sites people have produced (Bamboo Invoice etc) and it seems very powerful.

I have an application I'd like to develop but I'm finding some of the concepts a little hard to work out.

Simply, I'd like a 2 column CSS layout with a table of db records in each. Selecting a value in the table to the left, shows the related records in the table to the right.

I can code this in PHP quite simply, but the MVC approach of CI is confusing me a little.

Couple of questions I have:

* Whats the easiest way to pass the selected record from the left table to display related records in the other? Is all the code in the View, or the Controller / Model?

* I'd like buttons for "Add Record" etc that change the content of the right column depending on what button is clicked. Are templates the way to go here? In my brief learning with PHP I've used include files to achieve this.

Any pointers in the right direction appreciated.

Cheers
#2

[eluser]umefarooq[/eluser]
Welcome to CI
Just for your understanding about MVC is as
M for Model
model is you database layer with model you just simply interact with database fetch records, insert, update and delete records, simple database interaction,

V for View
view is you front end layer it contains html and programming code to display your results, its get parameters from controller to view data or results.

C for Controller
controller is logical or middle layer its communicate with both model and view your all code will be in controller, if you are dealing with database records first you have to call model with controller to fetch or update or delete record then the result will go to view to display result, if you are not dealing with database then you can call simple views from controller

for 2 or 3 column template you can call views in views

example in case of 3 columns
Code:
<div class="left">
  &lt;?$this->load->view('left',$pass_data_for_left)?&gt;
</div>
<div class="center">
&lt;?=$content?&gt;
</div>
<div class="right">
&lt;?$this->load->view('right',$pass_data_for_righ)?&gt;
</div>

all data parameters you can send through controller and you all 3 views are have html and php code
#3

[eluser]umefarooq[/eluser]
here is another smarter way to do this all stuff.

http://codeigniter.com/wiki/Header_and_F...ge_-_jedd/
#4

[eluser]nathanashton[/eluser]
Thanks guys.

I have a view that is passing a row id using the url helper.

The link is created as follows:
Code:
.anchor('/passengers/listpassengers/'.$row['sectorid']

This passes the URL passengers/listpassengers/(Rowid)

I'm using this in the listpassengers function:

Code:
$sector=$this->uri->segment(3);

I then want listpassengers function to run a DB query where the id=the returned Rowid.

What do I need in my model (get_where??) and what code would complete loading the model and sending the Rowid?

Hope that makes sense

Cheers
#5

[eluser]mattpointblank[/eluser]
Your model should have a function like this:

Code:
function getRow($id)
{
    return $this->db->get_where('table', array('id' => $id))->result_array();
}

Then in your controller you can access the data like this:

Code:
$this->load->model('Your_model');
$data['rows'] = $this->Your_model->getRow($id);
$this->load->view('your_view', $data);
// you can now access an array called $rows in your view.
#6

[eluser]nathanashton[/eluser]
Thanks Matt, exactly what I was looking for!

Cheers




Theme © iAndrew 2016 - Forum software by © MyBB