Welcome Guest, Not a member yet? Register   Sign In
Extending DB_Result
#2

[eluser]davidbehler[/eluser]
There is no easy way to extend the database drivers. They are not like the other libraries and not meant to be extended.

What you can do is edit the core files but you have to be careful here as new versions of CI may bring changes to files to edited and you would have to do this again.

In your case I guess I would go for a small function in a helper.
Let's say you put db_helper.php in your application/helpers folder and in this new file you could a new function like this:
Code:
<?php

function alter_index($result_array, $new_index)
{
  $new_result_array = array();
  foreach($result_array as $key => $value)
  {
    $new_result_array[$value[$new_index]] = $value;
  }

  return $new_result_array;
}
In your model you could use it like this:
Code:
function get_stuff()
{
  //...sql stuff
  return alter_index($res->result_array(), 'code');
}
Be aware that this is untested and as soon as (to use your example) 2 countries have the same code, the later one would override the first one and you would end up with less entries than you had before.


Messages In This Thread
Extending DB_Result - by El Forum - 09-24-2009, 01:09 AM
Extending DB_Result - by El Forum - 09-24-2009, 01:51 AM
Extending DB_Result - by El Forum - 09-24-2009, 05:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB