codeigniter – Digitalistic http://www.digitalistic.com Mashup or die trying Sun, 27 Apr 2014 04:03:01 +0000 en-US hourly 1 Two CodeIgniter libraries I can not live without http://www.digitalistic.com/2010/04/29/two-codeigniter-libraries-i-can-not-live-without/ http://www.digitalistic.com/2010/04/29/two-codeigniter-libraries-i-can-not-live-without/#comments Thu, 29 Apr 2010 08:00:15 +0000 http://www.digitalistic.com/?p=342 I have said it before and I say it again – “Hi, my name is Andreas and I am a CodeIgniter junkie”. I can quit my CodeIgniter (a PHP framework) habit whenever I want, but why would I want to (read Why I fell for CodeIgniter to know more)?

For the last few CodeIgniter projects (begagnadebarnkläder.nu – hitta billiga barnkläder for example) I have used two libraries that have made my life as a developer much easier and that I really recommend anyone using CodeIgniter take a serious look at. Those libraries are IgnitedRecord and BackendPro. They are not brand new, but they sure get the work done!

IgnitedRecord
IgnitedRecord is a ORM library that makes interacting with the database so much easier. Especially handling relationships between tables much easier to deal with, an example is getting all posts a user has written in a blog:

$posts = $user->related('posts')->order_by('name', 'desc')->get();

Nice and clean and very easy to setup, all you need to do is to have your models extend IgnitedRecord and then define the relationships in the model. Some other goodies are that it is very easy to make subqueries and nested WHERE statements.

Instead of going in to all the details here I think you should go and download IgnitedRecord straight away and get started, it will save you time.

BackendPro
Almost every project needs some kind of administration backend. With some frameworks (Django) you get this out of the box, not so with CodeIgniter unfourtunatly. BackendPro gives you that and so much more – it also helps out with things like user authentication and access rights, asset management, breadcrumbs, preference handling etc. Only the fact that it is an easy to setup and then handles basic user authentication (such as login, registration and forgotten password) is well worth the price of admission (which is nothing since it is all free). BackendPro also comes with the excellent Matchbox library, which lets you organize your code into modules.

Combining the two
Unfourtunatly the two do not fit perfectly together since BackendPro uses CodeIgniters standard database libraries, so if you need to do any database work with BackendPro itself you need to remember not to use IgnitedRecord. Getting the two libs to play nicely once they are installed is quite straight forward though…

  • Move the ORM() function from system/application/libraries/MY_Loader (a IgnitedRecord file) to system/application/libraries/Loader (a BackendPro file).
  • Delete the MY_Loader file
  • Optionally you could autoload the IgnitedRecord library
  • To make it all work I had to make a file called ignitedrecord.php in system/application/libraries that includes ignitedrecord/ignitedrecord, as per http://codeigniter.com/forums/viewthread/104123/#548669.

Do you have any other favorite libraries for CodeIgniter? Please let me and everybody else know in the comments!

]]>
http://www.digitalistic.com/2010/04/29/two-codeigniter-libraries-i-can-not-live-without/feed/ 4
Pimp my Coda http://www.digitalistic.com/2009/03/31/pimp-my-coda/ http://www.digitalistic.com/2009/03/31/pimp-my-coda/#comments Tue, 31 Mar 2009 09:23:41 +0000 http://www.digitalistic.com/2009/03/31/pimp-my-coda/ Coda is the best IDE I have ever used, and one (if not the biggest one) reason I am really happy with moving to Mac (sorry folks, Coda is Mac only). It does all the stuff I need, such as syntax highligthing, FTP, source control etc. At the same time it is skipping all the stuff that just clutters up the interface (like all the stuff Eclipse is full of). Some people might want more bells and whistles, but I am happy with a development tool that does just what it should and not more. I am mostly using Coda for writing things in the PHP Framework CodeIgniter or in the Python Framwork Django, but Coda can handle most languages quite nicely.

Coda

Even of Coda is great, it is not so great that it can not be made greater (so much for simplicity, hehe), which is pretty simple since Coda allows for plugins. In the Coda Developer Zone there are a number of plugins listed, and if you look around on the web you can find even more. Also, you can easily add new code completion, reference books and other goodies. This is a list of the stuff the extra stuff I have used and am very happy with so far…

URL Encode
This is a a very simple but very practical plugin that allows you to highlight some text in your HTML files and then URL Encode it. As a Swede using a lot of words with åäö it is very usefull.

PHP Toolkit
This plugin makes it easy to validate and clean up PHP files.

PHP Toolkit

CodeIgniter Syntax Mode
Code completion with CodeIgniter classes and functions, a must if you are using Coda to develop CodeIgniter applications. You can download the file here and read more about it in this thread in the CodeIgniter forums. I have made this syntax mode my default one for PHP files since I hardly do any PHP that is not CodeIgniter anymore.

Extra books
It is easy to include help files about programming languages etc in Coda in the form of “books”. Out of the box Coda comes with books about PHP, HTML, CSS and Javascript, but it is easy to add more. Here is a great list of more books you can include in Coda, complete with icons and all. Personally I have added CodeIgniter and jQuery so far, but I am sure some Django, Drupal and WordPress will sneak in as time goes by.

What are your favourite add ons to Coda? Please let me know if I have missed something I just must have!

]]>
http://www.digitalistic.com/2009/03/31/pimp-my-coda/feed/ 6
MashupCrowd – tracking who is talking about mashups http://www.digitalistic.com/2009/02/03/mashupcrowd-tracking-who-is-talking-about-mashups/ Tue, 03 Feb 2009 13:30:24 +0000 http://www.digitalistic.com/2009/02/03/mashupcrowd-tracking-who-is-talking-about-mashups/ The other day I launched MashupCrowd.com. It is a page that tracks who is talking about mashups on Twitter. I have been sitting on mashupcrowd.com and some other mashup .com domains for almost a year now, so it was about time to do something with (at least a few of) them. Inspired by svpt.nu – a very cool site that tracks Swedish Twitter users – I figured that I could do something similar but for mashups. That also gave me an excuse to finally dig into the Twitter API.

MashupCrowd - who is talking about mashups on twitter

It was extremely easy to get the interaction with Twitter to work using Twitters super simple Search API. As a basis for my PHP code I used Simon Maddox’s Codeigniter Twitter library to speed up development even more. Basically the backend is nothing more than a cron job pinging Twitters Search API every few minutes for new tweets and then saving them in a database. Considering doing something more with this data at a later stage, but for now I just show it on the site. What took the most time was not figuring out how to use the Twitter API or to write the few lines of PHP needed. What took me time was to get the site to look good using CSS, but I am quite happy with the end result. Hopefully I can do some more of my own CSS work in the future.

MashupCrowd has already proved usefull for me in finding new innovative mashups. Today I found a cool use of Twitter to track the snow depth in the UK.

]]>
Django installation gotchas http://www.digitalistic.com/2008/11/07/django-installation-gotchas/ http://www.digitalistic.com/2008/11/07/django-installation-gotchas/#comments Fri, 07 Nov 2008 12:43:18 +0000 http://www.digitalistic.com/2008/11/07/django-installation-gotchas/ In this blog I have earlier declared my love for both CodeIgniter and WordPress, but I am very unfaithful when it comes to frameworks and programming tools, so now I am testing out the Python framework Django instead (but I am still a newbie). It’s my experiences with Google App Engine that lead me into the Python/Django world, and when I am now considering what framework to use for an upcoming big project Django is definitly on the shortlist. It will not be a Google App Engine project due to that some of the limitations of that platform makes it a bad fit for the project in question, so it would be my first standalone Django project. So far I have only installed all the stuff I need and got it to play nicely together, but that was a real learning experience in itself, and by sharing it in this post I hope to save some other fellow geek some time and peace of mind.

Before getting started I want to thank Alexis Bellido at ventanazul.com for his patients with my Django questions, check out his post Django questions and answers with a Swedish guy for some more info on Django setup (if you didnt figure it out I am that Swedish guy).

Installation guides
When I set up Django locally I wanted to make my local development environment as similar to a production environment as possible, it will hopefully make production deployment easier down the line. To do this I am running Python 2.5, Django 1.0, PostgreSQL 8.3 (and thus the neccessary python driver psycopg2) and mod_python on Apache. There are some good installation guides out there, so setting up this stuff was mostly a walk in the park, check out the install guide in the Django Book, the quick install guide at Django Project or the install guide at WebMonkey. Of course there are some gotchas that took me quite some time to figure out…

Uninstall old versions of Django
Before getting started I already had Django 0.96 installed, and I  just installed Django 1.0 over it assuming that it was going to replace the old version. I was wrong and when I tried to run my new Django installation I got errors like “NameError: name ‘url’ is not defined” and “ImportError: cannot import name WEEKDAYS_ABBR” – neither which made much sense to me. It turns out that if you do not uninstall an old Django installation first you get a mix of new and old Django files, and that just do not work very well. So take care to acctually read and follow the instructions at Remove any old versions of Django.

Use the right version of the db driver (duh!)
To get the PostgreSQL working correctly with your Python install you have to use a version of the driver Psycopg2 that matches both your Python version and your Apache version, otherwise things just do not work and you do not really get a helpful error message. You can get the window versions of Psycopg2 here.

Configure Apache for mod_python
Once Django and Apache are installed you can create your new Django project (via django-admin.py startproject myNewProject) where Apache can find it (in htdocs for example). To be able to use Apache as your webserver you also need to install and configure mod_python. Installing is straight forward (see the install gudies above for more info), but configuring Apache took me some time. You need to edit httpd.conf and add the following to the end of the file:

<Location "/myNewProject">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /myNewProject
PythonDebug On
PythonPath "['C:\Program Files\Apache Group\Apache2\htdocs\myNewProject'] + sys.path"
</Location>

myNewProject is of course the name of your own Django project.

Hopefully this is of use to someone other than me, if not, then at least I have my notes organised for the next time. If I have missed anything or gotten anything wrong I would very much appreciate your feedback!

]]>
http://www.digitalistic.com/2008/11/07/django-installation-gotchas/feed/ 4
Use Akismet web services to fight spam http://www.digitalistic.com/2008/05/22/use-akismet-web-services-to-fight-spam/ Thu, 22 May 2008 13:12:29 +0000 http://www.digitalistic.com/2008/05/22/use-akismet-web-services-to-fight-spam/ As anyone that has surfed the web during the last years have noticed comment spam is wide spread, and highly annoying. Check the comments on blogs or web apps and you will find plenty of links left there by helpful people that really would like you to enlarge certain organs, sell you rolexxxes or need your help to get some dough out of Nigeria (I am the former prime ministers first bastard son, promise!). Fighting spam in your mail inbox is pretty simple these days, thanks to Thunderbird’s and GMails excellent anti-spam filters. Doing it in your WordPress blogs have also been a walk in the park for a long time, simply use the Akismet plugin you get with any WordPress installation and they will take care of it. Akismet is developed by Automattic (the company behind WordPress) and describes itself as “a big machine that sucks up all the data it possibly can, looks for patterns, and learns from its mistakes”. Send your comment data to them and they will compare it to their database and tell you if it is spam or not.

Now when I am writing some of my own web apps I would like to avoid spam to overwhelm me, both via contact forms and comments. Lo and behold, Akismet is available as a web service, and via some ready made libraries it is very easy to use from outside WordPress as well. I am using Elliot Haughin’s CodeIgniter Library, but there are also libraries for PHP, .NET, Ruby on Rails, Drupal etc etc. All you need to do is to get a Akismet API Key from WordPress.com (register, then go to My Account and Edit Profile and you will find the key), download a library (or start writing your own from Akismets API) and start sending all comments to Akismet. The API Key is free for personal use, cost $5/month if you make more than $500/month from your site and cost a bit more for Enterprises. Well worth it I say, it will save you time and frustration all around, and make your website so much cleaner. There is no longer any excuse to suffer comment spam.

Thanks Akismet for one of the best and most usefull web services around!

]]>
Why I fell for CodeIgniter http://www.digitalistic.com/2008/05/16/why-i-fell-for-codeigniter/ http://www.digitalistic.com/2008/05/16/why-i-fell-for-codeigniter/#comments Fri, 16 May 2008 10:51:47 +0000 http://www.digitalistic.com/2008/05/16/why-i-fell-for-codeigniter/ Since leaving Kapow a week and a half ago I have been coding more than I have for the last 3 years combined, and I have done it all in PHP using the framework CodeIgniter. I looked at quite a few frameworks, CakePHP and Ruby on Rails for example, and quite a few applications/blogging platforms/Content Management Systems that can be hacked and adapted, wordpress and Drupal for example. In the end CodeIgniter won the day, and so far I am extremenly happy with my choice. There are a handfull reasons why I prefer CodeIgniter:

  • It is PHP, this might be a dealbreaker for some, but for me that is a huge plus. Primarily the advantages of this is that I can easily host my creations on basically any cheap web host, that there are plenty of libraries and resources out there to make my life easier and also that I know PHP. For the last reason I could have gone with Ruby on Rails or Java as well, but it put all Python frameworks out of the competition.
  • CodeIgniter is very easy to install and as easy to deploy. All you need for things to play nicely is an Apache server, a MySQL database and a copy of the CodeIgniter files. Deploying and setting up things are the most boring thing when it comes to writing your own apps, so it is a must for me that it is a breeze, I just dont have the patience to deal with deployment problems.
  • Great documentation, the CodeIgniter user guide is excellent. This is a huge difference from many other frameworks and platforms, especially the ones developed by an open source community (CodeIgniter is developed by Ellis Labs, the guys behind the Expression Engine blogging platform). The developer community is also very active and knowledgable, so what isn’t in the user guide is in the CodeIgniter forums.
  • Finally, a framework that improves my productivity. Most frameworks tries to do to much and are so huge and rigid that there is a huge learning curve if you want to doing anything but a “Hello World” app. CodeIgniter helps me with the stuff I need help with and doesn’t meddle in the rest. There is no need to hack 10 plugins of different qualities together to get what I need (like in Drupal), and that just makes developing fun as it should be. It is also the first MVC (Model-View-Controller) framework that helps me organise my code in a good way, something that I usually suck at otherwise.

In short I recommend that anybody that knows PHP and want a light weight, good framework checks out CodeIgniter. A good place to start are the CodeIgniter video tutorials, and if you get a bit deeper into things Elliot Haughin has a great blog that often covers CodeIgniter and he also have some great libraries that are well worth looking at (CodeIgniter libs for Twitter, Flickr and Akismet for example). Another great resource is the blog of Derek Allard, Technology Architect at Ellis Labs.

]]>
http://www.digitalistic.com/2008/05/16/why-i-fell-for-codeigniter/feed/ 9