Return JSON with CodeIgniter

With the ever-increasing use of Javascript and AJAX related calls, it’s would be nice to be able to quickly build endpoints that returned JSON data for our web site. Whether your rolling your own code, using jQuery or using third-party tools like KendoUI, it’s very easy to return structured data in JSON format using CodeIgniter, a PHP framework from the fine folks at EllisLab.

CodeIgniter uses a simplified Model-View-Controller pattern to help you build websites quickly without worrying about the plumbing code that seems to go into every web site you build. In a typical CI web site, each page request, calls a controller which is responsible for determining what data gets loaded and which view of the data will be presented to the requester. When loaded, the model is responsible for determining how the data is retrieved. This data is then returned to the controller which passes it on to a View. Views are responsible for taking the structured data and formatting it for presentation to the user (typically in HTML).

Read more

Expense Reports Part 3 – Scripting

As part of our Expense Report Customization project, there are three main features that will need to be scripted:

  • Ensuring that the expense amount for personal auto mileage is calculated properly.
  • Verifying that the employee entered a value in the attendees field when selecting Meals and Entertainment.
  • Displaying an alert when line item thresholds have been reached.

We’ll look at each of these in detail and discuss the code and the reasoning behind our choices.

Read more