P2GR / datamapper

CodeIgniter Datamapper
Other
35 stars 23 forks source link

Is there a beta version of DataMapper ORM for COdeigniter 3.0 #1

Open mahmutbayri opened 10 years ago

mahmutbayri commented 10 years ago

Hi,

I'm stating a new project using codeigniter 3.0 development version. There is a message on http://datamapper.maglok.nl/ about DataMepper V2.

Do you have a beta version for V2? i know CI 3.0 currently is not released but allmost ready. if datamapper v2 beta/test is release It would be nice to test with framework. Maybe i will use Doctrine ORM, but i prefer your ORM because i think it uses codeigniter resource better than Doctrine.

Best regards

saekort commented 10 years ago

Hey,

I have just inherited the Datamapper library from Wanwizard. I am still setting up the github and the manual pages (the search does not work yet for example). So there might be some incorrect information on there for a while.

That said, I do not think there is any code for a 2.0 yet. It would require a full re-implementation and the question is if that is worth it for Codeigniter. I will do my best to support Datamapper 1.8.x though! :)

mahmutbayri commented 10 years ago

Thank you for answer.

Could you check if it works with CI 3.0-dev? I use load_class in Common.php (CI3.0), and add these lines to APPPATH.'third_party/datamapper/bootstrap.php' to initialize without error.

// Do we have a DataMapper extension for this class?
if (file_exists($file = DATAMAPPERPATH.'third_party/datamapper/system/'.$class.'.php'))
{
    require_once($file);
}

When i wanted to write simple query like $user->get_by_id(1); i am getting an error

 Fatal error: Call to undefined method DM_DB_mysqli_driver::_where() in W:\www\MynetTVAdmin\html\application\third_party\datamapper\system\DB_driver.php(66) : eval()'d code on line 20

If this library is compatible with CI3.0-dev, i am going go open issues about my problem.

Thanks.

saekort commented 10 years ago

Datamapper 1.8.2 is not compatible with CI 3.0-dev. The error you get is because CI 3.0 handles database connections differently then CI 2.x does and Datamapper 1.8.2 is very dependant on core CI functionality that is changed in CI 3.0-dev.

If CI 3.0-dev actually gets to a release then we can see what we'd have to change to get it to work on 3.0.

dsivic commented 9 years ago

it is time...

saekort commented 9 years ago

Wow that I'd see the day. :) I shall look into this!

fven commented 9 years ago

Any news about this?

jamieburchell commented 9 years ago

I recently got DM working with CI3. It's not fully tested, nor can I guarantee there aren't any bugs, but feel free to check it out:

https://github.com/jamieburchell/datamapper/tree/ci3

arsenbagratyan commented 9 years ago

Hi. I have put this version in my project, after it I get such a problem http://prntscr.com/7b4cb7. Tried to find the reason. When I comment http://prntscr.com/7b4d81 this line it doesn't show this error, just sure that it isn't right way. Can you help me pls?

Thanks.

jamieburchell commented 9 years ago

Hi. Did you replace all your datamapper files including the Datamapper.php (class DataMapper) library file from my fork? Are you able to provide me with the query code you are using which generates this error? Thanks Jamie

arsenbagratyan commented 9 years ago

Thanks Jamie for your reply.

http://prntscr.com/7brqix In the old versions DM $function were equal 'where', but now it's equal to '_where'. I've changed t but think it isn't the best solution, is it?

http://prntscr.com/7brqvb And there is problems with '$this->load'.I've made it '$this->ci_load'.

jamieburchell commented 9 years ago

It doesn't look like you're using the files from my fork

https://github.com/jamieburchell/datamapper/blob/ci3/application/libraries/datamapper.php

And yes, it's ci_load and ci_config

saekort commented 9 years ago

I am sorry for not having had time to check this out guys. I will as soon as possible!

saekort commented 9 years ago

@jamieburchell I am checking out your fork changes. I grabbed a nice clean copy of CI3 and tried getting it to work but so far it is having issues with the fact the Router class is not available in the bootstrap.php on line 90.

I shall now delve into it myself as well, I got a bit of time and this deserves some of our attention afterall.

jamieburchell commented 9 years ago

@saekort Not sure what could be causing that, I'm not seeing it with CI3 and the HMVC extension.

saekort commented 9 years ago

I grabbed the current CI3, no extension. I know of the extension, I just figured go with the barebones here. Is the HMVC extension required? It does seem that the Router not being available is a known Datamapper with CI3 thing though...

saekort commented 9 years ago

Alright for some reason Datamapper is trying to load the Router class without a CI_ prefix. I get a lot more working if I force a prefix. Though this is not a preferred solution. Investigation continues.

Got it. The Router class is loaded differently in CI3, it takes a third parameter, thus walking all over the 'CI_' prefix set by the datamapper load_class. We can work around that with some sort of exception, but what I cannot figure out is that this works for you @jamieburchell It shouldnt :)

jamieburchell commented 9 years ago

I'm not aware that HMVC would be a requirement - if you look at my changes there aren't really many from your existing repo...

https://github.com/saekort/datamapper/compare/master...jamieburchell:ci3

saekort commented 9 years ago

Your changes so far look very promising.

The only thing I cannot understand is that Router loading works for you. So the datamapper bootstrap.php has the load_class function like this:

function &load_class($class, $directory = 'libraries', $prefix = 'CI_')

Codeigniter 2.2.X loads the Router like this

/*
 * ------------------------------------------------------
 *  Instantiate the routing class and set the routing
 * ------------------------------------------------------
 */
    $RTR =& load_class('Router', 'core');
    $RTR->_set_routing();

    // Set any routing overrides that may exist in the main index file
    if (isset($routing))
    {
        $RTR->_set_overrides($routing);
    }

But Codeigniter 3.X does it like this:

/*
 * ------------------------------------------------------
 *  Instantiate the routing class and set the routing
 * ------------------------------------------------------
 */
    $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);

Thus Codeigniter 3.x uses the third variable in such a way Datamapper will not like.

jamieburchell commented 9 years ago

I see. Mine also requests "Router" without a "CI_" prefix, but afterwards it loads "App_Router" which I'm guessing masks that issue.

To be honest, I'm not sure why DM is overwriting this function anyway? I guess it needs changing though to be compatible if it is required.

Edit: Oh it's overwritten because of:

// Do we have a DataMapper extension for this class?
...
jamieburchell commented 9 years ago

I think this would be OK?

https://github.com/saekort/datamapper/commit/7f367cf7e288e35b1e378cb16e162fd6a9a3c8d1

Basically using the current CI3 function and added the DM specific stuff

saekort commented 9 years ago

I think what the original author might have thought of with the $prefix variable is that 'CI' is a customizable string, or perhaps something with the 'MY' extensions.

That looks like a good solution to me + some comment text fixes it seems. Works for me.

saekort commented 9 years ago

If you don't mind jamie, I have created a branch on the project and added your changes to it. I will use it to test and change a few things in the docs (for example I would add you as a contributor in the code :))

We'd leave it open for testing for a while and if no issues are found we can go for a proper release. Thanks for your work so far, it is appreciated. My bucketlist is just too long at the moment. :)

jamieburchell commented 9 years ago

Sounds like a plan. I'll be using it in anger in my CI3 project and will of course contribute back any bug fixes / issues if they arise :)

arsenbagratyan commented 9 years ago

Sorry. Have you check it on linux?

saekort commented 9 years ago

You mean datamapper and CI3.0? I have not yet, but I don't think there would be many problems, since the core did not change and there is not really any input/output to disk.

Regardless it should be tested on linux so feel free to do so arsenbagratyan. :)

jamieburchell commented 9 years ago

Yes, checked in a pure Linux environment - hence the need to change class name loading to ucfirst

arsenbagratyan commented 9 years ago

I've changed file name and class name. I've test it on windows it works, but there are errors in Linux, when $this->load->library('datamapper');

arsenbagratyan commented 9 years ago

http://prntscr.com/7btv1w this is the screenshot

saekort commented 9 years ago

I am running on windows at the moment myself and I am not having this issue. What code you got running and what webserver? Are we talking IIS here?

I believe I remember seeing that error before in relation to datamapper somewhere.

jamieburchell commented 9 years ago

Also not seen this on Linux with Apache and PHP 5.5.24

arsenbagratyan commented 9 years ago

I've tried ci3 branch https://github.com/jamieburchell/datamapper/tree/ci3

saekort commented 9 years ago

Could you give us a bit more to go on then? You tried that branch (which is atm also on this repo/dev_ci3), but what exactly were you running on, what was the code you were trying. Cannot reproduce it at the moment, because I am not having the problem.

arsenbagratyan commented 9 years ago

I've tried in simple HMVC, I have running https://github.com/jamieburchell/datamapper/tree/ci3 this code. It aren't errors in windows, but it has problem with has_many. when I use it it brings empty array, but it musn't be so

arsenbagratyan commented 9 years ago

I've find this dev_ci3 branch https://github.com/saekort/datamapper/tree/dev_ci3 . I've tried it too, but there is the same issue conected with has_many

saekort commented 9 years ago

That is because it is effectively a copy, as I mentioned before as well.

Can you give us the exact model you are working with and then the code you use to get these relations?

arsenbagratyan commented 9 years ago

Hey, I've found the error's reason. Now everything works fine :) You helped me much. Thanks guys

saekort commented 9 years ago

What turned out to be the problem? Anything we have to change?

arsenbagratyan commented 9 years ago

I have some problem in my code, have corrected them, during debug I noticed this http://prntscr.com/7cxz5h . But don't think it has main role. But now as there is solved my problem I don't continue work on checking it, as have much to do now. And have changed some conditions like this http://prntscr.com/7cz96u . If you want I can send you the file. Thanks for your support

saekort commented 9 years ago

What exactly is wrong with a statement like $CI->load->model($class) ?

arsenbagratyan commented 9 years ago

$this->{name} = new $class(); it couldn't create the object. Think it's connected with autoload, as I have done several changes in the autoload

saekort commented 9 years ago

You have to leave the autoload models array empty, perhaps that is it?

saekort commented 9 years ago

@arsenbagratyan I think I have had the same problem now. It is that PHP requires 5.5 to be able to do something that Datamapper does on row 4029 of the latest build:

empty($this->db->dm_get('qb_orderby')

Effectively this issue: http://stackoverflow.com/questions/1075534/cant-use-method-return-value-in-write-context

Will fix.

saekort commented 9 years ago

PS: It only pops up on PHP < 5.5

pwrfix commented 8 years ago

Hi there,

I've just upgraded to CI 3.0.2 and ended up having to remove Datamapper completely to get my app to work in my environment again.

The main issue was that each time it attempted connection to the MySQL instance (via mysqli) it hung the MySQL server. Not sure why - mysqltuner.pl reported that my app wasn't closing connections correctly and I noticed that there was code removed with something to do with closing or managing connections?

@saekort, will this project be continued to be maintained and developed for CI 3.x.x? I'd love to see a stable release and re-integrate.

Cheers,

Craig.

RikBlank commented 8 years ago

Hi saekort, me too love to see a version of this datamapper for CI3. It's simply my favorite :)

also I like to mention this repo was difficult to find because the documentation on many places still points to wanwizard.

cosmomathieu commented 8 years ago

Where are the instructions on how to install this for CI3?

inieves commented 6 years ago

id also really like to see Datamapper for CI3. As far as I can see, lack of DM is the primary reason I have no benefit from moving to CI3.

jamieburchell commented 6 years ago

Use the https://github.com/saekort/datamapper/tree/dev_ci3?files=1 branch, it works fine with CI3. I've contributed to that code to make it compatible and have been using it in a couple of big CI3 projects without issue.

inieves commented 6 years ago

Thanks for that input. I can certainly do that.

Out of curiousity, why is it a dev branch and not something stable? What would it take to get there?

On Aug 27, 2018, at 4:29 AM, Jamie Burchell notifications@github.com wrote:

Use the ci3 dev branch, it works fine with CI3. I've contributed to that code to make it compatible and have been using it in a couple of big CI3 projects without issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

inieves commented 6 years ago

Sorry, I mean why use the dev branch and not something stable? Does datamapper not work on stable?

On Aug 27, 2018, at 8:17 AM, Ian Morris Nieves imnieves@gmail.com wrote:

Thanks for that input. I can certainly do that.

Out of curiousity, why is it a dev branch and not something stable? What would it take to get there?

On Aug 27, 2018, at 4:29 AM, Jamie Burchell notifications@github.com wrote:

Use the ci3 dev branch, it works fine with CI3. I've contributed to that code to make it compatible and have been using it in a couple of big CI3 projects without issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.