ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DataMapper ORM v1.8.2

November 30, 2011 3:43pm

Subscribe [100]
  • #61 / Dec 23, 2011 1:59pm

    AdamM

    5 posts

    2. You need to add the bootloader to your index.php, this creates the DM_DB_Driver, it should always be there.

    When you get to the lines that generate these errors, $this->db should already be loaded. What is your db_params value when this happens? And how and where do you define it?

    I added bootloader to index.php.

    I set db_params for example like this:

    Array ( [hostname] => localhost [username] => SOME_LOGIN [password] => SOME_PASS [database] => SOME_DB [dbdriver] => mysql [dbprefix] => [pconnect] => [db_debug] => 1 [cache_on] => [cachedir] => [char_set] => utf-8 [dbcollat] => utf8_general_ci [swap_pre] => [autoinit] => 1 [stricton] => )

    Normal connection string. When I use tables from default database, it’s ok, but when I set db_params to use another database, then I’ve got errors I mentioned.

  • #62 / Dec 23, 2011 6:38pm

    WanWizard

    4475 posts

    I can reproduce it now. I’m looking for a fix.

    edit: think I fixed it. I just pushed the fixes to BitBucket. Could you download ‘tip’ again and see if it works for you now?

  • #63 / Dec 24, 2011 6:17am

    AdamM

    5 posts

    I can reproduce it now. I’m looking for a fix.

    edit: think I fixed it. I just pushed the fixes to BitBucket. Could you download ‘tip’ again and see if it works for you now?

    Now it’s working! Thank you!

    PS. I like DataMapper very much :D.

  • #64 / Dec 24, 2011 7:32am

    WanWizard

    4475 posts

    Ok, thanks for the feedback. Merry Christmas.

  • #65 / Dec 28, 2011 9:50pm

    Frank Wong

    31 posts

    Just upgraded to DM 1.8.2 and CI 2.1.0 and everything works great except for loading a DataMapper extension. I get

    An Error Was Encountered
    DataMapper Error: loading extension array: File not found.

    I am not sure where the extensions should live. I have copied the extension files to CI application/datamapper. Am I missing some configuration to indicate where to find the extensions?

    Thanks.

  • #66 / Dec 28, 2011 10:19pm

    Frank Wong

    31 posts

    I figured out the offending code. It is the fact that if line 922 in library/datamapper.php is a file that exists, then it will not hit

    if ( ! file_exists($file))
       {
        if(strpos($name, '/') === FALSE)
        {
         $file = APPPATH . DataMapper::$config['extensions_path'] . '/' . $name . EXT;
         $ext = $name;
        }
        else
        {
         $file = APPPATH . $name . EXT;
         $ext = array_pop(explode('/', $name));
        }
    
        if(!file_exists($file))
        {
         show_error('DataMapper Error: loading extension ' . $name . ': File not found.');
        }
       }

    that sets var $ext. That bombs when line 948 refers to it.

    if(class_exists($prefix.$ext))

    My ugly hack to get it to work for now is to force to go into the if statement by setting

    $file = '';

    right after line 922

    $file = DataMapper::$config['extensions_path'] . '/' . $name . EXT;

    Again, this is an ugly hack.

  • #67 / Dec 28, 2011 11:03pm

    Nguyen Huy

    3 posts

    That should solve the problem.

    Otherwise, load the database library in the welcome controller, and var_dump(get_class($this->db)). What class is it pointing too? It should be “DM_DB_Driver”. If you see “CI_DB_Driver”, the bootstrap isn’t loaded, or isn’t loaded properly.

    Note that DataMapper 1.8.2 requires CI 2.0.3 or above.


    Hi, This is the result.
    It is string(12) “DM_DB_Driver” when i execute var_dump(get_class($this->db)).

    But this bug [Fatal error: Call to undefined method CI_DB_mysql_driver::dm_call_method() in C:\wamp\www\examples\application\libraries\datamapper.php on line 1113] still occurs.
    This bug occurs when i try to load a function that does not exist in the path controllers/admin_module/manage.php. localhost/mysite.com/admin_module/manage/function_no_exist for example.

    Note: Setting 404_override in routes.php file is $route[‘404_override’] = ‘home’;

     

  • #68 / Dec 29, 2011 5:10am

    WanWizard

    4475 posts

    @Frank Wong,

    which version of the code do you have? Line 922 in mine is a bracket-close.

    You can run into this issue if you have specified a fully qualified path for ‘extensions_path’ in your datamapper config. Try defining it relative to APPPATH (so just ‘datamapper’ in your case) to work around it.

    It can be fixed by adding an else:

    if ( ! file_exists($file))
    {
        // existing code here
    }
    else
    {
        $ext = $name;
    }
  • #69 / Dec 29, 2011 5:13am

    WanWizard

    4475 posts

    @Nguyen Huy,

    do you autoload the database in your config, manually in your controller, or do you have Datamapper handle it?

    Which version of CI are you using? I’ll see if I can find the time to reproduce it.

  • #70 / Dec 29, 2011 6:28am

    elmizan

    7 posts

    Can I combine this plugin with ionAuth? I see the structure of database table seems same. any suggestion where I’m start

    DataMapper doesn’t supply any tables, so I’m not sure what you mean.

    But in general it is no problem mixing normal CI active record calls and using a DataMapper model to interact with the table. You only have to make sure the relation structure isn’t broken (foreign keys updated/reset/etc) when you access the tables directly.

    For complex operations, I normally use direct AR calls in my DataMapper model methods, as they are faster that ORM operations. If needed DataMapper provides a method to convert a standard CI $this->db result into DataMapper objects.

    I mean the ion Auth (authentication) library.

  • #71 / Dec 29, 2011 7:59am

    WanWizard

    4475 posts

    I don’t see a reason why IonAuth should be using ORM models. All the database I/O is internal to the library, so what happens there is not really relevant.

    Nobody’s stopping you creating a model for IonAuth’s tables, so you can access them outside IonAuth using DataMapper.

  • #72 / Dec 29, 2011 1:02pm

    Frank Wong

    31 posts

    @Frank Wong,

    which version of the code do you have? Line 922 in mine is a bracket-close.

    You can run into this issue if you have specified a fully qualified path for ‘extensions_path’ in your datamapper config. Try defining it relative to APPPATH (so just ‘datamapper’ in your case) to work around it.

    It can be fixed by adding an else:

    if ( ! file_exists($file))
    {
        // existing code here
    }
    else
    {
        $ext = $name;
    }

    I am using DM 1.8.2 installed from sparks and CI 2.1.0.

    This is the entire _load_extensions() function in datamapper.php

    protected static function _load_extensions(&$extensions, $names)
     {
      $CI =& get_instance();
      $class_prefixes = array(
       0 => 'DMZ_',
       1 => 'DataMapper_',
       2 => $CI->config->item('subclass_prefix'),
       3 => 'CI_'
      );
      foreach($names as $name => $options)
      {
       if( ! is_string($name))
       {
        $name = $options;
        $options = NULL;
       }
       // only load an extension if it wasn't already loaded in this context
       if(isset($extensions[$name]))
       {
        return;
       }
    
       if( ! isset($extensions['_methods']))
       {
        $extensions['_methods'] = array();
       }
    
       // determine the file name and class name
       $file = DataMapper::$config['extensions_path'] . '/' . $name . EXT;
                            $file = ''; // TODO: FW - ugly hack to make loading extensions work. Need to remove when there is a fix.
       if ( ! file_exists($file))
       {
        if(strpos($name, '/') === FALSE)
        {
         $file = APPPATH . DataMapper::$config['extensions_path'] . '/' . $name . EXT;
         $ext = $name;
        }
        else
        {
         $file = APPPATH . $name . EXT;
         $ext = array_pop(explode('/', $name));
        }
    
        if(!file_exists($file))
        {
         show_error('DataMapper Error: loading extension ' . $name . ': File not found.');
        }
       }
    
       // load class
       include_once($file);
    
       // Allow for DMZ_Extension, DataMapper_Extension, etc.
       foreach($class_prefixes as $index => $prefix)
       {
        if(class_exists($prefix.$ext))
        {
         if($index == 2) // "MY_"
         {
          // Load in the library this class is based on
          $CI->load->library($ext);
         }
         $ext = $prefix.$ext;
         break;
        }
       }
       if(!class_exists($ext))
       {
        show_error("DataMapper Error: Unable to find a class for extension $name.");
       }
       // create class
       if(is_null($options))
       {
        $o = new $ext(NULL, isset($this) ? $this : NULL);
       }
       else
       {
        $o = new $ext($options, isset($this) ? $this : NULL);
       }
       $extensions[$name] = $o;
    
       // figure out which methods can be called on this class.
       $methods = get_class_methods($ext);
       foreach($methods as $m)
       {
        // do not load private methods or methods already loaded.
        if($m[0] !== '_' &&
          is_callable(array($o, $m)) &&
          ! isset($extensions['_methods'][$m])
          ) {
         // store this method.
         $extensions['_methods'][$m] = $name;
        }
       }
      }
     }

    Is the sparks version 1.8.2 not the version everyone else is referring to?

    Thanks.

  • #73 / Dec 29, 2011 1:28pm

    Frank Wong

    31 posts

    I found and downloaded the zip from http://datamapper.wanwizard.eu/pages/download.html and indeed the libraries/datamapper.php are different from the version from sparks. It also explains a lot why some of the instructions on setup/upgrade seem to not make sense. I think the sparks setup is slightly different.

    Is the sparks version not current and should not be used? I do like how sparks keeps third_party modules (mostly) separated from my application code. Thanks.

  • #74 / Dec 29, 2011 7:07pm

    WanWizard

    4475 posts

    There were some post-release fixes, some of them might not have made it to the spark. I’ll see if I can update it…

  • #75 / Dec 29, 2011 11:48pm

    Frank Wong

    31 posts

    There were some post-release fixes, some of them might not have made it to the spark. I’ll see if I can update it…

    You are awesome. Thanks for updating this project. It is very useful.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases