CodeIgniter Composer Twig Doctrine

Its not always the power of a framework, its (human) resource that acts as key factor for final selection. On such cases the best option is to add the best things from the new framework and incorporate with the selected one. I really liked symfony2 components and wanted to have that in my CodeIgniter pack also wanted to leverage the power of composer.

After digging and headbanging for few hours; its a SUCCESS. So now my pack relies on composer’s autoload, uses twig template engine and uses doctrine.

Here are my code : ( 99% are of others I just patched those for my need )

Thanks guys for your hard work which saved tons of hours for me. Here are the references:

  1. http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter
  2. https://github.com/dilantha/codeigniter-twig
  3. http://www.joelverhagen.com/blog/2011/05/setting-up-codeigniter-2-with-doctrine-2-the-right-way/

I will try to update this code based on issues i face. Do let me know if anything  is missing or needs any modification.

Debugging CodeIgniter Project using Xdebug and Netbeans

Finding the right way to debug PHP projects has always been a hot topic. Primitive solutions like `echo`, `print_r`,`var_dump` has always been the power tool 🙂 for my type of ppl .  Let us forget those painful nights and go to a quick debugging solution with Xdebug and Netbeans 6.8; in a 1-2-3 step guide for CodeIgniter.

What i am expecting from you:

  • You already have a running web server [ Xampp/WAMP/ Uniform server ]
  • You know how to install Netbeans IDE 6.8 or it’s already running in your environment
  • You know what is CodeIgniter
  • You are not a complete Newbie

# STEP – 1

First add extension Xdebug in PHP. Download latest stable Xdebug version from Xdebug.org. Follow the procedures. If you are lazy like me and don’t want to read the whole thing [it’s a bad habit 🙂 ] copy the following settings and put at the end of your php.ini by not forgetting to change the path 🙂

zend_extension_ts="C:/wamp/bin/php/php5.2.9-1/ext/php_xdebug-2.0.4-5.2.8.dll"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

Note: If anything messes up later; come back and study those links over and over till u understand the whole thing.

# STEP – 2

Configure CodeIgniter to accept ‘?XDEBUG_SESSION_START=netbeans-xdebug’. You can follow one of my post or check in codeigniter forums for accepting GET data in CodeIgniter.

Start Netbeans IDE. Goto Tools >> Options >> PHP >> General: and check for settings in Debugging section. By default the port should be 9000 and Session-ID ‘netbeans-xdebug’.

#STEP -3 [ FINAL 😀 ]

Let’s say, You have installed a ‘test’ CodeIgniter application in your web server. Now add that application as a project in Netbeans 6.8 . Goto Project properties by right clicking on the project ‘test’.  Now go to ‘Run Configuration’ and click ‘advanced’  select ‘Ask Every time’ in Debug URL.

Now Open your ‘welcome’ controller and press ‘Ctrl+F5’ which will request for the URL:

specify url

insert ‘http://localhost/test/’  and press ‘Ok’.  Next select `Server side PHP`.

Clicking in ‘Debug’ button will open ‘http://localhost/test/?XDEBUG_SESSION_START=netbeans-xdebug‘ In you default web browser.

Now check in status bar for:

And check in toolbar for:

If those 2 shows up then u have successfully installed Xdebug+Netbeans. Your IDE is ready to do some debugging. Take your cursor over a line on index function of welcome.php; press ‘F4’ this will execute php scripts till that cursor. Dont worry if index.php is opened up focusing on first line.

Now You can watch for variables or step into functions or step over. You can check your code line by line.

Read this link which have brief discussion on what options you have for Debugging :).


My counting on steps could be wrong 🙂 .. bt it looks nice 1-2-3. I tried not to explain a lot; so for more details study provided links.  I hope this will make your life more easier. Enjoy !!

Another Captcha Library for CodeIgniter

One of our client wanted a different captcha in his website. We were using the default captcha plugin which bundles with CodeIgniter. I have used this script on a different project long ago and that one was a scratch coding. So, i took some of my time and ported it to CodeIgniter.

Features:

  • Change the Captcha Background Color
  • Choose Font / Random Font from fonts folder
  • Increase Number of lines for Noise Creation
  • Different color or custom colors for Line used for Noise.
  • Captcha Letters have different colors or you can provide your own color set.
  • Custom Image Height/Weight/Font-size
  • Many more…

Expected Look :

Captcha CI libraray

Captcha CI libraray

Requirment: CodeIgniter 1.7.* , GD, PHP 4/5

SOURCE CODE: In github [ How to  Use?  Check wiki page. ]

CodeIgniter and GET Method working to-gether

This is a personal note kind of post.. So, those who knew already about this… just can skip.. 🙂 . But for a short summary, to use the power of GET method by not setting the CI as Query string based URL. 

Target To achieve: 

http://localhost/myapp/mycontroller/mymethod/?possible=yes

create file MY_Input.php in your application/library/
[ Reason: SO that CI does not destroy GET Method ] 

<?php
class MY_Input extends CI_Input {
    function _sanitize_globals()
    {
        $this->allow_get_array = TRUE;
        parent::_sanitize_globals();
    }    
Change following variable in your Config.php 
$config[‘permitted_uri_chars’] = ‘a-z 0-9~%?=&.:_\-‘;
$config[‘index_page’] = “”;
.htaccess File [ Thanks to Adnan ]
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
Some Workaround: 
1. If you want to accept GET data in your controller’s index method.. have to use 
Reference:
It worked out fine for me. My CI version is : 1.6.3

Another Asset Helper with Dependency for CodeIgniter

A huge collection of JQuery, Mootools and other javascript frameworks plugins helps enhancing the user experience.  But everything comes with a drawback. Too many plugins and their dependant js and css files. Usually when you start working on a real life project, sooner it gets crowded with over 10 to 15 js files cause you are using many plugins like: lightbox, accordion, portlet, ajax form, form validation .. etc.  An asset helpers comes up with a helping hand. It helps to manage the js, css files and you can load particular js, css files necessary for that particular page.

I was looking for a suitable solution for such asset management. I found some, but those focused on managing the folder wise specification of js and css files on individual plugins. Still,  in the matter of loading particular plugins, you have to select the js & css files for that particular plugin individulally.

Here is an idea with a library to manage assets based on plugins. It mainly focuses on dependency and plugin component.  The plugins totally depends on the config file set by the developer.  Here is the config file:

$config[‘component_location’] = array(
‘js’ => ‘rabbit-assets/’,
‘css’ => ‘css/’,
);

$config[‘component_mandatory’] = array(
‘template.css’
);

$config[‘component_list’] = array(
‘thickbox’ => array(
‘resource’ => array( ‘thickbox.js’, ‘thickbox.css’ ),
‘dependency’ => array( ‘jquery.js’ ),
),
‘facebox’ => array(
‘resource’ => array( ‘facebox.js’, ‘thickbox.js’, ‘facebox.css’),
‘dependency’ => array( ‘jquery.js’ ),
)
);

First the component location has to be set relative to base_path(). Then you can set the mandatory js & css files. These files will always be in views. Then in component list define the plugins with their resource of js and css files and their dependent js or css files.

Now in controller load the library and helper:

$this->load->library(‘component’);
$this->load->helper(‘component’);

To load a particular component call :  $this->component->add_component(‘thickbox’);  To add multiple components write again: $this->component->add_component(‘facebox’);

At last to print the <link> and <script> files in your view just write this in your view file:

<?=print_components();?>

The library itselft priotorizes and prints js and css files. It handles duplicate files too.

I am planning to integrate it with some other features from other Asset libraries but it will be great if someone adds this to their asset library.

Please comment if there is any bugs.      Source Code

Rabbit Form Modification

I like Rabbit Forms for it’s simplicity and extendability.Today I am going to show you a modified RabbitForm library to achieve the following effect. This is actually taken from one of my project … but little modified. Let’s says: I have a quiz with options. Each quiz will have multiple Options 1:N relation. As you may know Rabbit Forms has a DropDown list that can be used to achieve such operation. But I wanted little easier one, i dont’ wanted to click and select the parent table relation everytime. A little more flexible and effective solution. Check the following Steps To see my modified form. By the by, I did not used a custom form view. The default options and some tweaking with the Rabbitform library did all the trick.

Step1:
 Code: $this->rabbitform->retrieve(‘quiz.yml’); 



Step 2:
code:
function quiz_manage( $quiz_id ) {
    $html = $this->rabbitform->run(‘quiz.yml’, $quiz_id);
    $html .= ‘<br />’;
    $html .= $this->rabbitform->retrieve(‘option.yml’, 0,
                array( “tbl_quiz_id = $quiz_id”),
                array(
                    ‘manage’ => “quiz/option_manage/$quiz_id/”                
                )
            );
    $this->masterpage( $html );
}
Note:
   the retrieve function now can accept 2 more extra parameters. 3 rd parameter represents the new filter which only shows the options of that particular quiz. And 4th parameter defines the location of option’s manage path.
 

Step 3:

code :
function  option_manage( $quiz_id, $option_id = false )
{
      $rundata = $this->rabbitform->run(‘option.yml’, $option_id,
                array(‘tbl_quiz_id’ => $quiz_id),
                array(
                    ‘manage’ => “quiz/option_manage/$quiz_id/”                
                )                
        );
      if( $rundata )  $this->masterpage( $rundata );
      else  $this->quiz_manage( $quiz_id );
}

 

Note:
Here  ‘run’ method accepts 3rd  parameter which defines the hidden values.



Get the Rabbitform.php from download section and overrite with the original one in application/library folder. Rabbit Forms version is If any bug or problem occurs let me. Till now i haven’t found any problem.

Planning to create my first screencast on CodeIgniter

I am planning to make my first screencast. Here is my rough plan:

Desktop Tools I will use:

  1. Camtasia ( for screen capture )
  2. Total Commander
  3. DBdesigner 4
  4. uniserver

CodeIgniter :

  1. CodeIgniter 1.6.3
  2. BackendPro
  3. RabbitForms
  4. Jquery Pagination

Online Resource: 

  1. Oswd ( Open Source web design ) for template

Hopefully the outcome will be a blog.. before 18October. [ Apology: due to sudden crisis(personal) i am postponing the screencast till november 15. I am really sorry. But i will upload the necessary files before the screencast. This will give a glimpse of what i was trying to do.]

P.S. Do post your suggesstion.