Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6706515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:31:46+00:00 2026-05-26T07:31:46+00:00

I’m looking at using DataMapper ORM with CodeIgniter, but have a scenario where the

  • 0

I’m looking at using DataMapper ORM with CodeIgniter, but have a scenario where the database structure is poorly formed.

I’d like to be able to configure my model to map the database field names, to something more logical. Then, when we get around to updating the database structure, I can just update the model, and all the referencing code will continue to work.

Is this possible with DataMapper ORM?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:31:47+00:00Added an answer on May 26, 2026 at 7:31 am

    Yes it is possible. I can explain the logic and how your can tackle the problem using a custom core class for the codeigniter application.

    Create a file inside application/core/ and label it Mapdm.php

    write the following inside the file.

    class Mapdm {
    
    
        private $map_fields = array();
    
    
        function __construct($modelClass_name, $map_fields = array()){
    
            $this->_model = new $modelClass_name(); /* instantiate Model */
            $this->map_fields = $map_fields;
    
        }
    
        function __get($name){
            if(isset($this->map_fields[$name])){
                $name = $this->map_fields[$name];
            }
    
            return $this->_model->{$name};
    
        }
    
        function __set($name, $value){
    
            if(isset($this->map_fields[$name])){
                $name = $this->map_fields[$name];
            }
    
            return $this->_model->{$name} = $value;
    
        }
    
        function __call($name, $args){
    
            return call_user_func_array(array($this->_model, $method), $args);
        }
    
    
    }
    

    To use this in your controller, simply instantiate this class as show below inside the controller constructor class. To simplify table field map data in the array, you may choose to store the array data inside a custom config file.

    example. map_field_config.php (file contents)

    $config['mapfield'][{modelname}] = array ('fieldA'=>'real_fieldname', 'fieldB'=>'real_fieldname2');
    

    controller file setup

    class ControllerName extends CI_Controller{
    
        function __construct(){
    
           parent::__construct();
    
           $mapfields = $this->config->item('mapfield', $mapfields);
           $model_fields = $mapfields['mymodel'];
    
           $this->mymodel = new Mapdm('mymodel');
    
        }
    
        function index(){
    
          $records = $this->mymodel->get();
    
    
           }
    
     }
    

    I have not tested this code, however I just wrote it to give you an idea. It is like creating a wrapper object for Datamapper model and calling the methods and properties using the wrapper. The wrapper should always check and return the correct table field name to the datamapper object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.