Extracting the ActiveRecord Library from CI |
[eluser]Nathan Pitman (Nine Four)[/eluser]
I'm no PHP Guru but I get on really well with CI as a framework that allows me to achieve so much more than I would be able to with raw PHP. Recently I've been working on a small project where it would be a great benefit to be able to use the ActiveRecord Library from CI 'without' the overhead of Code Igniter itself. I don't need models, views or controllers but just a nice quick, easy and familiar way to access DB records. If anyone here has any experience with extracting the AR library and has a simple example that they could post here, it would be greatly appreciated. Once I'm able to get something working I'd be more than happy to write up a Wiki article for the benefit of other newbies like myself. ![]()
[eluser]gerben[/eluser]
Try this tutorial: http://hasin.wordpress.com/2007/06/13/us...deigniter/ It worked for me!
[eluser]Nathan Pitman (Nine Four)[/eluser]
Hi gerben, I did give this tutorial a shot but I kept getting errors at line 18 of ActiveRecordFactory.php. Code: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/xxxxxxxx/public_html/webservices/database/ActiveRecordFactory.php on line 18 If you have any example source files that you could provide it would be most helpful as this looked like a great solution from Hasin's write up. As a bit of a newb when it comes to CI I think I just need some clarification! I was wondering if perhaps the solution wasn't comp with CI 1.6. Perhaps I'm doing something wrong but I double and triple checked that I had followed the instructions correctly. :/
[eluser]John Fuller[/eluser]
I have been sounding like a broken record these days but I would take a look at the Zend DB. This is exactly what the Zend library is good for. Use CodeIgniter if you need a completed framework and use the Zend library if you just need individual pieces.
[eluser]xwero[/eluser]
[quote author="John Fuller" date="1203708446"]I have been sounding like a broken record these days but I would take a look at the Zend DB. This is exactly what the Zend library is good for. Use CodeIgniter if you need a completed framework and use the Zend library if you just need individual pieces.[/quote] You should ask the people from Ellislab to sticky that last sentence ![]()
[eluser]Nathan Pitman (Nine Four)[/eluser]
John, thanks for the pointer but I'm using PHP4 and the ZF is PHP5+ I think. Does look interesting though. With regards to the problem I'm having above. I managed to locate the example files that Hasin provided for the tutorial (http://javapark.net/hasin/ActiveRecord.zip) and I'm still none the wiser. Any chance someone might be willing to give this a shot themselves and see if it works for them?
[eluser]gerben[/eluser]
I've uploaded the code for you: http://www.zomp.nl/downloads/engine.zip. I did it with the CI 1.5.4 database library, so I'm not sure if it works for 1.6's. I've changed hasin's code a bit, to make it even easier to call and use! This is how you use it: include("path/to/config.php"); include("path/to/init.php"); Then you just go: $db->where('id', $id); $db->orderby('order_id'); $query = $db->get('attachments'); etc! Works like a charm ![]()
[eluser]Nathan Pitman (Nine Four)[/eluser]
Thanks gerben, just downloaded that now and will give it a shot. Looks much smarter...
[eluser]Nathan Pitman (Nine Four)[/eluser]
Ok, I must being doing something daft... I have a folder called 'webservices' and an index file inside that with: Code: <?php Then the files that you provided which also reside in the same folder as the index.php. I'm still getting that same parse error at line 18: Code: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/xxxxxxxx/public_html/webservices/database/ActiveRecordFactory.php on line 18 Any ideas?
[eluser]gerben[/eluser]
Are you on php4? php4 doesn't support private or public classes, so that might be your problem. |
Welcome Guest, Not a member yet? Register Sign In |