Welcome Guest, Not a member yet? Register   Sign In
Joins: Controller or Model?
#10

[eluser]Denarius[/eluser]
[quote author="wish_bear" date="1267664633"]Actually you can use traditional SQL Statement in CodeIgniter to create join statements much easier (as for me) to replace the built in active record methods found in CI, you can refer on this part of the CI User Guide (found in the below link).

Code:
$query = $this->db->query("SELECT b.fieldA as fieldA, b.fieldB FROM table1 a, table2 b WHERE a.id = b.id");

foreach ($query->result() as $row)
{
    echo $row['fieldA'];
}

http://ellislab.com/codeigniter/user-gui...eries.html

Let me know if it helps![/quote]

I've just reread this post and suddenly realised that with a custom query, each row is returned as an array in contrast to using a
$this->$db->get('tablename') which returns rows as objects corresponding to the table (i.e. $row->fieldname. I recognise that it's just as easy to echo the values in the view either way, but with a manual query would you normally create a class yourself to keep the model in line with how the framework does things?

Many thanks for the discussion, it's very thought-provoking.


Messages In This Thread
Joins: Controller or Model? - by El Forum - 03-02-2010, 08:50 AM
Joins: Controller or Model? - by El Forum - 03-02-2010, 08:54 AM
Joins: Controller or Model? - by El Forum - 03-02-2010, 10:08 AM
Joins: Controller or Model? - by El Forum - 03-02-2010, 03:12 PM
Joins: Controller or Model? - by El Forum - 03-03-2010, 12:45 PM
Joins: Controller or Model? - by El Forum - 03-03-2010, 01:03 PM
Joins: Controller or Model? - by El Forum - 03-03-2010, 05:28 PM
Joins: Controller or Model? - by El Forum - 03-04-2010, 11:01 AM
Joins: Controller or Model? - by El Forum - 03-04-2010, 11:13 AM
Joins: Controller or Model? - by El Forum - 03-04-2010, 05:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB