Skill Tag: CodeIgniter
PHP Check for an AJAX call
I just learned that it’s possible to check in php if a request has been made through an ajax call which is handy when you want to return a different template depending on if it’s ajax or not. To do it you just add this snippet:
function is_ajax(){
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}
Good CodeIgniter Google Maps API V3 Library
I found a pretty cool library to help you print out google maps on your sites. You can find it here.
CodeIgniter Loops
I discovered a nice method of looping out data in CodeIgniter. I set up a loops module and created a load of view files to handle different loop styles. That way I can print them out anywhere in the site by adding:
<?php $this->load->view('loops/loopname'); ?>
Makes it work a bit like WordPress’ get_template_part() function.
Tank Auth for CodeIgniter
Tank Auth is an excellent user authorisation library for CodeIgniter. It’s saving me a shit load of time.
HMVC in CodeIgniter
Switched my main CodeIgniter project to HMVC this week, it’s much handier for larger sites.
_remap method in CodeIgniter
If you need to customise your URLs in a controller in CodeIgniter you can do it easily by adding an _output method to the class. Then you can fill it with if statements using the variables passed in the URL and call different functions using it.
CodeIgniter Admin Panel
Currently looking at Bonfire, it looks like a handy admin panel for CodeIgniter.