Tag Archives: codeigniter

CodeIgniter, MySQL and User-Defined Variables

The lesson for today is… how to sort records sequentially on a numeric column and provide the ability to move records up and down in the existing sort order.

There are 2 functions I use for manual record sorting to change the display order in admin/user areas. The following example is based on a “pages” table and the commands are located in a model. For this example, the table has the following fields: page_id (int), page_sort (smallint), page_title (varchar), and page_content(text).

Continue reading

Table/record sorting made easier for CodeIgniter

In a project I am currently working on, I needed a way to efficiently allow sorting of the records in an admin area while preserving the functionality of a search function (that passes the query in the url) and the pagination library. Initially it started off as a section of each method where sorting was allowed (record lists of things like countries, states, etc). My sorting routines finally ended up being put into their own helper.

Continue reading

Codeigniter Image_lib convert() v1.3 JPG to GIF to PNG

I recently performed some code-fixing for a library extension I found over in CodeIgniter’s forum. The mod provided a convert() method for the Image_lib library. It lets you to convert (duh) the original image from/to JPG (default), GIF or PNG and optionally delete the original image.

When I first added this extension into my CI distribution, everything still worked without throwing errors so I started calling the new function. Then…

Continue reading

Convert extended ASCII in a string using PHP strtr instead of Normalizer or iconv

I am working on a CodeIgniter project that has information stored in the database with extended ascii characters (128-255) and UTF-8 encoding. As most of you know, CodeIgniter is fairly strict on what is allowed in a url (they only allow what SHOULD be permitted per RFC 1738 ;)). Furthermore sunce you can create basically any character by allowing a percent sign (%) in the URL, alowing that was not a viable option for me.

For instance you cannot use “ñ” (n with a tilde) in the URL parameters. Replacing it with “n” for the database query will however return a valid match. Problem solved! I can just use Normalizer or iconv, right?

Continue reading

Codeigniter Core Mod for $_SERVER[‘DOCUMENT_ROOT’] on GoDaddy subdomains with $_SERVER[‘SUBDOMAIN_DOCUMENT_ROOT’]

I was tinkering around with a CodeIgniter project earlier today and at some point, I needed to use PHP’s file_exists() function. I tend to use $_SERVER[‘DOCUMENT_ROOT’] for my starting location for finding files located in the web-viewable areas (makes sense huh?). This makes it easy to get the file url by simply replacing the document_root from the path of the filename which results in a nice absolute path for linking. In this particular instance, I was checking for an image to show in place of a heading tag. Granted the code was simple and straight forward, but it could not get PHP to locate the file and I knew it was there.

Continue reading