Welcome Guest, Not a member yet? Register   Sign In
CI, MVC and m:n table-relationships
#1

[eluser]eff_kay[/eluser]
Hi guys!

I'm completely new to the MVC-pattern and frameworks in general. I'm working on a project and I figured I'd give it a go with Codeigniter. So far I've only done procedural programming, so the MVC pattern is a bit alien to me. Bear with me, please.

Okay, I'm going to use an example to try and explain:

I've got three tables:
tableA (id, name, description)
tableB (id, difficulty, situation)
tableAB (tableA_id, tableB_id)

.. and I've got a model which interacts with the tables. The model has a function for each table:
function a() gets everything from tableA
function b($id) uses $id to select everything from tableB where $id = tableAB.tableA_id and tableB_id = tableAB.tableB_id

Okay, so far everything is Hunky Dory. I've set up my controller with functions to interact with the model. One of these uses "function a" from the model to produce an array containing tableA's content. I then send this to a view and echo it as a list of links. These links point to another function in the controller like this:

Code:
anchor('controller/functionForTableB/' . $tableA_content->id, $tableA_name)

Here's how the code for functionForTableB would look like:
Code:
function functionForTableB()
{
  $id = $this->uri->segment(3);
  $data['tableB'] = $this->model->b($id);

  $this->load->view('viewname', $data);
}

Here's where I get stuck. I've got two more tables:
tableC (id, type)
tableBC (tableB_id, tableA_id)

So this connects tableB and tableC in the same way that tableA and tableB is connected. I want functionForTableB to be able to use data from tableC as well. I created a new function in the model ("function c"). This function does the same as "function b" does (only for tableB and tableC of course). I need to provide the correct id from tableB and send it to the SAME view.

Code:
function functionForTableB()
{
  $id = $this->uri->segment(3);
  $data['tableB'] = $this->model->b($id);
  $data['tableC'] = $this->model->c($howDoIGetThisIdFromTableB);

  $this->load->view('viewname', $data);
}

Hope this makes sense. Kinda difficult to explain exacly what I need to do.
-FK-


Messages In This Thread
CI, MVC and m:n table-relationships - by El Forum - 06-08-2009, 05:45 PM
CI, MVC and m:n table-relationships - by El Forum - 06-08-2009, 05:56 PM
CI, MVC and m:n table-relationships - by El Forum - 06-08-2009, 08:29 PM
CI, MVC and m:n table-relationships - by El Forum - 06-08-2009, 08:50 PM
CI, MVC and m:n table-relationships - by El Forum - 06-08-2009, 08:56 PM
CI, MVC and m:n table-relationships - by El Forum - 06-09-2009, 06:23 AM
CI, MVC and m:n table-relationships - by El Forum - 06-09-2009, 07:28 AM
CI, MVC and m:n table-relationships - by El Forum - 06-09-2009, 10:02 AM
CI, MVC and m:n table-relationships - by El Forum - 06-09-2009, 10:36 AM
CI, MVC and m:n table-relationships - by El Forum - 06-09-2009, 11:31 AM
CI, MVC and m:n table-relationships - by El Forum - 06-09-2009, 12:00 PM
CI, MVC and m:n table-relationships - by El Forum - 06-09-2009, 02:13 PM
CI, MVC and m:n table-relationships - by El Forum - 06-10-2009, 05:30 AM
CI, MVC and m:n table-relationships - by El Forum - 06-10-2009, 06:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB