| CARVIEW |
Last 15 Articles
- CodeIgniter 1.7.0 Released
- CodeIgniter Community Voice - HOWTO: Set up a CodeIgniter project in Subversion
- CodeIgniter Community Voice - Generating PDF files using CodeIgniter
- CodeIgniter Community Voice - Lee’s Lost Bet
- CodeIgniter Community Chieftain Michael Wales
- CodeIgniter Brazil
- CodeIgniter Community Voice - Mathew Davies
- CodeIgniter 1.6.3 Maintenance and Security Release
- CodeIgniter Community Voice - Michael Wales
- Japanese CodeIgniter book
- CodeIgniter Community Voice - Elliot Haughin
- Wiki Article Discussions Added
- CodeIgniter v1.6.2 Released
- EllisLab Hiring, Two Positions Available
- ExpressionEngine 2.0: fully CodeIgnited!
Feeds
Blog & News
CodeIgniter 1.7.0 Released
Code Igniter Version 1.7 has been released. This version contains a number of new features and enhancements, as well as many small improvements and bug fixes. For a list of all changes please see the Change Log.
If you are currently running Code Igniter please read the update instructions.
Note: If your browser does not display the 1.7 user guide please clear your cache and reload the page.
Posted by Rick Ellis on October 23, 2008
CodeIgniter Community Voice - HOWTO: Set up a CodeIgniter project in Subversion
EllisLab is blessed with two of the greatest communities that can be found anywhere on the internet in ExpressionEngine and more recently CodeIgniter. Despite being a relative newcomer to the scene, the people attracted to CodeIgniter are among the smartest, most talented and down-to-earth developers around today. From time to time we want to highlight some of these talented people, and we’ve asked them to lend their voice to ours. Have your voice. I hope you enjoy what they have to say as much as I did.
This week, our Community Voice author is Bruce Alderson, known on the forums as madmaxx, who has written a wonderful guide on how he uses subversion with CodeIgniter. Bruce is an elder web monkey and systems programmer. He totally digs the craft of building software, making cool stuff, and causing people to laugh so hard liquids are forced from their nose. He’s currently the Chief Monkey at Discovery Software and author of the not-at-all famous robotpony.ca. (Go read the one about shaving your yak)
After working with CodeIgniter for a few months (and WordPress for a few years), I’ve settled on a way to set up web projects that works well for development, deployment, and source control. Note that this style of layout only works on systems like Mac and Linux that have useful symlinks.
First, the folder layout
some-domain.com/
app/
config/
controllers/
(etc)
public/
.htaccess -> ../site-extras/.htaccess
favicon.ico -> ../site-extras/favicon.ico
js/ -> ../site-extras/js
images/ -> ../site-extras/images
system/
application/ -> ../../app/
site-extras/
js/
images/
.htaccess
The layout favours a vhost setup, and splits your code and resources out of the CodeIgniter sources. Splitting your stuff from the CodeIgniter stuff lets you link your Subversion repository to theirs, so that you can keep it in sync with their development.
How it’s done
- Set up your source tree (not including the symlinks or CodeIgniter source) and add to your Subversion repo.
- Add a svn link to CodeIgniter’s repo (via svn propedit svn:externals, with public https://dev.ellislab.com/svn/CodeIgniter/tags/v1.6.2/) and run a svn update to grab the framework. See the Subversion docs for details.
- Copy the CI application folder to the site root (as app), remove the .svn folders, symlink to application, and add it to your local svn repo.
- Symlink the other site-extras to the public webserver root, and configure your local machine (and public webserver) to point to this root for the domain’s virtual host setup.
- Alternatively, you can modify the $application_path to point to ../public/app/ (I’m not sure which is better yet). See the CodeIgniter docs on apps for more details.
You now have a CodeIgnitor project ready for development. You can keep up-to-date with CodeIgniter updates, deploy easily, and get at your code without wading through extra levels of hierarchy.
Posted by Derek Allard on August 15, 2008
CodeIgniter Community Voice - Generating PDF files using CodeIgniter
EllisLab is blessed with two of the greatest communities that can be found anywhere on the internet in ExpressionEngine and more recently CodeIgniter. Despite being a relative newcomer to the scene, the people attracted to CodeIgniter are among the smartest, most talented and down-to-earth developers around today. From time to time we want to highlight some of these talented people, and we’ve asked them to lend their voice to ours. Have your voice. I hope you enjoy what they have to say as much as I did.
This week, our Community Voice author is Chris Monnat, known on the forums as mrtopher, who writes a helpful step by step guide to generating PDF files from CodeIgniter. Chris is a full time web application developer and part time entrepreneur. In addition to building web sites for the medical industry during the day, at night Chris also runs his own development company Left of Center Communications. He recently started a personal blog at https://www.chrismonnat.com where he keeps a record of his exploits and discusses, among other things, CodeIgniter.
PDF files rock! Some of the programs used to view them could use some work, but the file format itself is real handy. As a programmer I have found PDF’s to be most helpful when generating reports that need to be printable. I know we are all supposed to be doing our part to make our offices “greener” and use less resources like paper. But some things just need to be printed (especially when your talking about the financial and legal industries).
When generating reports in PDF format you suddenly have a lot more control over layout and design than you do with plain old HTML and CSS (although much progress is being made with print style sheets). You can create some really nice reports on the fly that your users can view, save for later or e-mail to their co-workers for review. In this post I will show you how I generate PDF reports using CodeIgniter.
Quick Note
There are a number of PHP libraries out there for generating PDF files (like FPDF, Panda and dompdf) but the best one I have come across is the R&OS pdf class. I was first introduced to it from the PHP Anthology first edition by Harry Fuecks. I have tried other PDF libraries (some PHP 5 specific and some not) and none of them have been able to provide me with the same control or ease of use that the R&OS class has which is why I’m using it for this tutorial.
Getting Started
Before we start, lets get everyone to the same place so you can follow along as we go. I’ve prepared a .zip file containing everything you’ll need to follow along. The archive includes CI 1.6.3 along with all the code and libraries we will discuss in this tutorial. Simply download the archive, unzip it on your web server and follow along.
I have done all the work of downloading the code library and putting the files in their right place for you, but I wanted to mention where things were for the detail oriented among you. There are 2 files that are necessary in order to use the R&OS library: class.ezpdf.php and class.pdf.php. Those two files have been placed in the application/library folder. R&OS also requires some font files in order to function and they have been placed at the root of the .zip file in a folder called fonts.
You do have to make a minor modification to the class.ezpdf.php file so that it will work properly within CI. First I renamed the file to cezpdf.php, which makes it easier to load using the CI loader. Then you have to modify the include statement on line 3 to:
include_once(APPPATH . 'libraries/class.pdf.php');
This will keep PHP from saying that it can’t find included file. Once those modifications are made the R&OS class is ready to use with CI.
In the archive, I have also made a controller called tutorial.php and a helper called pdf_helper.php both in their respective directories. With the background info. out of the way, lets get our hands dirty with a real simple example.
Hello World
function hello_world()
{
$this->load->library('cezpdf');
$this->cezpdf->ezText('Hello World', 12, array('justification' => 'center'));
$this->cezpdf->ezSetDy(-10);
$content = 'The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.
Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.';
$this->cezpdf->ezText($content, 10);
$this->cezpdf->ezStream();
}
The above code produces a PDF file like this. In the above, first thing we do is load the R&OS library for use. Next we use the ezText() function to create a title for our document. This function takes the text it will display as the first argument, the size of that text and an optional array of additional configuration options. In this instance we pass along a justification option of center. That will center our title at the top of our document. After the title we insert some extra white space using the ezSetDy() function. After the whites pace we put the rest of the content for the document in a variable called $content and add it to our document using the ezText() function again. Finally, we create our document using the ezStream() function which actually creates the document and sends it to the users which prompts them to view/download the generated PDF document.
Handling Tabular Data
When your dealing with business reports the odds are good that you will need to generate reports with tables to display tabular data. From my experience with other PDF libraries, this is not an easy task. But with the R&OS library it’s about as hard as creating an array.
function tables()
{
$this->load->library('cezpdf');
$db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
$db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
$db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');
$col_names = array(
'name' => 'Name',
'phone' => 'Phone Number',
'email' => 'E-mail Address'
);
$this->cezpdf->ezTable($table_data, $col_names, 'Contact List', array('width'=>550));
$this->cezpdf->ezStream();
}
The above code should produce a PDF file like this. In the above code I create an array of data called $db_data. I put this together so that it imitates a typical database result set because that’s usually where you will be getting your data from. Below my data array I have created a $col_names array that associates the data elements in the $db_data array with a column title for the table. This is where the R&OS gets the title to display at the top of each table column. Once I have the data and column titles I create the table by calling the ezTable() function. This function takes the data array, an associative array for column names, the title for the table and an optional array of configuration options. There are a number of options that can be configured through that last optional array, but I’m not going to go into them in this tutorial.
Headers and Footers
Most reports in a corporate setting come with some kind of standard header and/or footer. They can include anything from the date/time generated, the user who generated them, to page numbers and the like. Headers and footers are handy to have, but unfortunately there isn’t a real good way to add them to printable reports generated in HTML and CSS. There’s one more reason to use the portable document format when creating printable reports. The process of adding headers and footers to a PDF using the R&OS library is the slightest bit complicated. There are a lot of lines of code just to accomplish it, that’s why I have created a helper file. Since the code is in a helper function, you just need load the helper and call the function whenever you need to add headers/footers to a PDF.
function prep_pdf($orientation = 'portrait')
{
$CI = & get_instance();
$CI->cezpdf->selectFont(base_url() . '/fonts');
$all = $CI->cezpdf->openObject();
$CI->cezpdf->saveState();
$CI->cezpdf->setStrokeColor(0,0,0,1);
if($orientation == 'portrait') {
$CI->cezpdf->ezSetMargins(50,70,50,50);
$CI->cezpdf->ezStartPageNumbers(500,28,8,'','{PAGENUM}',1);
$CI->cezpdf->line(20,40,578,40);
$CI->cezpdf->addText(50,32,8,'Printed on ' . date('m/d/Y h:i:s a'));
$CI->cezpdf->addText(50,22,8,'CI PDF Tutorial - https://www.christophermonnat.com');
}
else {
$CI->cezpdf->ezStartPageNumbers(750,28,8,'','{PAGENUM}',1);
$CI->cezpdf->line(20,40,800,40);
$CI->cezpdf->addText(50,32,8,'Printed on '.date('m/d/Y h:i:s a'));
$CI->cezpdf->addText(50,22,8,'CI PDF Tutorial - https://www.christophermonnat.com');
}
$CI->cezpdf->restoreState();
$CI->cezpdf->closeObject();
$CI->cezpdf->addObject($all,'all');
}
An example of how I use this helper is provided in the headers() function of the tutorial.php controller. That code produces a PDF file like this. The above code is the prep_pdf() function located in the pdf_helper.php file. This function does all the hard work of creating a footer for my PDF reports for me. All I have to do is load the helper in my controller and call the function. Since the reports could be portrait or landscape I have also included the ability to pass the orientation to the function and the code will modify the document margins accordingly. I’m not going to go into a lot of detail about the above code because this tutorial could become very long. But the general idea is that I’m using the R&OS library to modify the margins of the document I’m creating, add page numbers and text to the very bottom of the document. R&OS has some functions that makes this easy like ezStartPageNumbers() and line(). Once all that is done I can add any kind of content to the document back in my controller and then just call ezStream() to generate the final document.
Wrap Up
I barely scratched the surface of what you can do with the R&OS PDF library in this tutorial. I encourage you to spend some quality time with the readme.pdf documentation file that comes with the library when you download it. That file goes over all the functions and their options in great detail. So there you have it, generating PDF files with CodeIgniter and the R&OS library. If this method doesn’t quite do it for you, there are a few helpful articles on the CodeIgniter wiki, like this one and this one, which walk you through some additional options. Whatever solution you choose I hope this tutorial has helped to introduce you to some of the options you have at your disposal for creating PDF reports with CodeIgniter. Discuss this articlePosted by Derek Allard on July 31, 2008
CodeIgniter Community Voice - Lee’s Lost Bet
EllisLab is blessed with two of the greatest communities that can be found anywhere on the internet in ExpressionEngine and more recently CodeIgniter. Despite being a relative newcomer to the scene, the people attracted to CodeIgniter are among the smartest, most talented and down-to-earth developers around today. From time to time we want to highlight some of these talented people, and we’ve asked them to lend their voice to ours. Have your voice. I hope you enjoy what they have to say as much as I did.
This week, our Community Voice author is Lee Tengum, who discusses how CodeIgniter has cost him over $8,800 in beer and soft drinks. Lee is a bit of a serial entrepreneur, with 5 successful startups under his belt including the recently launched https://cleverandy.com. He has become something of a cookie! jar of startup knowledge. When he is not managing his team of contractors he blogs about the trials and tribulations of his startups at https://tumbledry.ca.
It all started with an idea at 4 a.m. on a Tuesday morning that brought us to CodeIgniter.
We were neck deep in a deadline and sinking fast. We knew we needed help.
After puling some strings that bought some time we quit work for a week - well, client work at least. There were our own issues to solve.
We had amassed a team of roughly 14 at this point and had no way to efficiently manage who was doing what for how much and how long; in fact we were often surprised by code submissions.
That’s a sad place to be.
We had been building in the ‘flavor of the weak’ when it came to frameworks and often chose whatever the contractor was fluent in to save time (which != saved money).
Not only were we not communicating, but we were reinventing the wheel for every project. Have I mentioned how sad of a place that is to be?
Back to 4 a.m.
Doug is one of my closest friends, and a trusted peer. He suggested we should develop a contractor management system and that we should build it all on CodeIgniter. At this time I hadn’t seen sleep in nearly a day, consumed almost seven liters of coffee, the “development tub” was empty and we were trying to finish a RoR project that a contractor bailed on. I didn’t want to hear about another &^%in framework, I just wanted this to be done.
Thankfully my friend couldn’t understand the word “no” and kept pressing. He went on about how anyone with knowledge of PHP can build with this, its development cycle and the community that was forming around it. I still wasn’t convinced but he assured me this would be the last time we changed frameworks and proposed a friendly bet.
I hate that I love gambling. I don’t have a problem, per say, but I always lose. The problem is that my pride drives me to bet anyways. Besides I relished the opportunity to prove him wrong.
So the bet was laid. We would build the contractor management system in CI and all client projects for one month with CI. At the end of that month if I wanted to go back to another framework and could justify it rationally with solid points then he would keep the Development Tub full for a full year (a cost of roughly $100/week). If we stayed with Code Igniter I would the one stocking the tub for the next year and I would also have accept his offer to buy into my company and become a partner.
On Wednesday morning we filled the tub (again not a problem… really) and set out to build our app. We outlined what we wanted, mapped it out on the whiteboard, set up a Basecamp project for it, defined our milestones and set Saturday as launch day.

Beer? Check.
Monster energy drinks? Check.
Coffee? Check.
M&M Peanuts? Check.
Babysitter? Check. (We’re parents…)
Pizza? Maybe.
Basecamp set up? Check.
SVN Server? Check.
While I depleted the tub and read the user guide, Doug was getting down to business. By the time I’d figured out how I was going to tackle my portion of the build he’d built the user authentication as well as the management section. Doug was already adding features to our “Wish List” in Basecamp and checking off milestones. Roughly 9 hrs into our project we started completing items on the wish list, which had never happened before. The wish list had never become a checklist before a deadline and I was starting to worry.
In the wee hours of Thursday morning we headed home to sleep. The following day we sent login details to our contractors and set up a basecamp project to log bugs. We fixed the stupid little ones that we missed and made changes on the fly. By the end of the day I had a huge overview of our team of contractors and a vision of things to come. I never did see the 48 hr Milestone reminder emails from Basecamp… again I was seeing a change.
By the end of the month we had more than a few client sites built on CI. We also had a process for development laid out and the term Rapid Development was taking on meaning with me. I was happy, the clients were happy and we had a team we could manage… and then reality sunk in.
I hate losing, even more so I hate losing to people I like winning against. I lost the bet. Though I gained a valuable business partner, a managed team, profitability and a kick ass framework to build it upon… I am forever filling the tub.
And with ExpressionEngine 2 built on CI (Which we are using extensively for client sites now), the tub has gained a lifetime sponsor. Me.
That app was build on 1.4.0 on September 20th 2006 and since then we have revised many things including our checklist:
Beer? Check.
M&M Peanuts? Check.
Basecamp set up? Check.
SVN Server? Check.
See the difference? We don’t live at the office any more. CodeIgniter gave us the freedom to build around our needs and wants and it gave us the structure we needed to become more efficient. Just don’t bet against CI, it has cost me $8800 and counting…. weekly.
ABOUT LEE
Lee is a bit of a serial entrepreneur, with 5 successful startups under his belt including the recently launched https://cleverandy.com. He has become something of a cookie! jar of startup knowledge. When he is not managing his team of contractors he blogs about the trials and tribulations of his startups at https://tumbledry.ca.
Posted by Derek Allard on July 21, 2008
CodeIgniter Community Chieftain Michael Wales
We’re happy to announce a new program for exceptional members of the CodeIgniter community, CodeIgniter Community Chieftains. As the community grows, the EllisLab development team often does not have the time that we would like to interact with the community in various ways, but it’s always been a key part of our success. So as the need arises, we have created this program to help keep the wheels greased so to speak, making sure that our forums, wiki, and bug tracker are handling the needs of the community and are properly moderated.
This is an invitation only program as the aforementioned link explains, and we’re proud to bring Michael Wales on board as our first CodeIgniter Community Chieftain. Most will need no introduction to Michael as you have likely already encountered him or some of his contributions in the community. Welcome aboard, Michael!
Posted by Derek Jones on July 17, 2008
