RSS

Category Archives: Codeigniter

Link

http://kennykee.com/138/codeigniter-resize-and-crop-image-to-fit-container-div-example/

Advertisements
 
Leave a comment

Posted by on September 14, 2015 in Codeigniter

 

Tags:

DataTables Server Side Processing with CodeIgniter

DataTables

DataTables

In this tutorial, we will see how to use popular dataTables with CodeIgniter framework. Note that, pagination is done in client side for this tutorial. Hence this example is not ideal for a big data set. Handling pagination in server side will be discussed in  a future tutorial.

Table format

                             <th>Need identified thru</th>
                                        <th>Total Estimate</th> 
                                        <th class="no-sort"></th>
                                        <th class="no-sort"></th>

                                    </tr>
                                </thead>

                            </table>

Initializing and fetching data with ajax


<script>
    $(document).ready(function() {
        $('#dataTables').dataTable({
            "ajax": "<?php echo base_url('test/get_json'); ?>",
            "pageLength": <?php echo $this->config->item('results_per_page'); ?>,
            "order": [[ 0, "desc" ]],
            "aoColumnDefs": [
                { "bVisible": false, "aTargets": [0] },
                {
                    "bSortable": false,
                    "aTargets": ["no-sort"]  
                }],
            "dom": 'T<"clear">lfrtip',
            tableTools: {
                "sSwfPath": "<?php echo base_url("plugins/data_tables/extensions/TableTools/swf/copy_csv_xls_pdf.swf"); ?>"
            }
        });
});
</script>

Test Controller

class Test extends CI_Controller {
public function get_json() {
        $this->load->model('test_model');
        $results = $this->test_model->load_grid();
        $data = array();
        foreach ($results  as $r) {
            array_push($data, array(
                $r['rname'],
                $r['year'],
                $r['mname'],
                $r['need'],
                $r['total_cost'],
                anchor('test/view/' . $r['id'], 'View'),
                anchor('test/edit/' . $r['id'], 'Edit')
            ));
        }

        echo json_encode(array('data' => $data));
    }
}

Model

class Test_model extends CI_Model {
public function load_grid() {
        $this->db->select("$this->tbl_urgent_needs.unid,$this->tbl_urgent_needs.year,$this->tbl_urgent_needs.needi,$this->tbl_urgent_needs.total_cost,$this->tbl_maintenance_type.name AS mname,$this->tbl_roads.name AS rname");
        $this->db->from("$this->tbl_urgent_needs");
        $this->db->join("$this->tbl_roads", "$this->tbl_roads.rid = $this->tbl_urgent_needs.rd_id");
        $this->db->join("$this->tbl_maintenance_type", "$this->tbl_maintenance_type.id = $this->tbl_urgent_needs.maint_type_id", "left");
        $this->db->order_by("$this->tbl_urgent_needs.unid", 'ASC');

        $query = $this->db->get();
        return $query->result_array();
    }
}

 
2 Comments

Posted by on May 20, 2015 in Codeigniter, PHP

 

Tags:

Passing Multiple Parameters to Form Validation Custom Callbacks in Codeigniter

Codeigniter Custom Callbacks

Codeigniter Custom Callbacks

CI natively only allows for  single parameter in custom callbacks. For an instance see the following code.

$this->form_validation->set_rules
('hstate', 'State', 'required|callback_suburb_check[' . $suburb . ']');

If you need to pass multiple parameters, you have several options. Obviously you can change CI behaviour by subclassing the core library. But in this tutorial we follow the less pain approach. That ‘s to access required parameters via POST variables within your custom callback function. They are still available in this scope.

There is another way using your PHP string handling knowledge. Just formatting all the parameters as single string and passing to the callback function.

$parameters = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
$this->form_validation->set_rules
('some_field', 'Some Field Name', 'callback__my_callback_function['.$parameters.']');  

Then in your callback,

function _my_callback_function($field_value, $second_parameter){
    list($first_param, $second_param, $third_param) = split('||', $second_parameter);
    ...
}
 
Leave a comment

Posted by on June 30, 2014 in Codeigniter

 

Tags: ,

How to remove index.php from CodeIgniter URL in Ubuntu

Codeigniter

CodeIgniter

 

In application/config/config.php change:

$config['index_page']='index.php';

to:

$config['index_page']='';

 

Create or modify .htaccess in project root with following content.

# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

Also allow overriding htaccess in your apache

/etc/apache2/sites-available/default

and edit the file & change to

AllowOverrideAll

and

Restart Apache

 

sudo /etc/init.d/apache2 reload

or:

sudo service apache2 reload

or:

sudo /etc/init.d/httpd reload
 
1 Comment

Posted by on May 3, 2014 in Codeigniter

 

Tags:

HTML Email with Codeigniter

$this->email->to( 'abc@gmail.com' );
$this->email->subject( 'Test' );
$this->email->message( $this->load->view( 'email/message', $data, true ) );
$this->email->send();
 
Leave a comment

Posted by on June 18, 2013 in Codeigniter, PHP

 

Tags:

Codeigniter configuration for PostgreSQL Database

 

First enable Postgresql extension in php.ini
extension=php_pgsql.dll

You also can enable Postgresql extension for PDO as well.
extension=php_pdo_pgsql.dll

If you forgot to enable this you may come across following error.

A PHP Error was encountered

Severity: Warning

Message: require_once(C:/www/system/database/drivers/postgres/postgres_driver.php) [function.require-once]: failed to open stream: No such file or directory

Filename: database/DB.php

Line Number: 138

Now opendatabase configuration file. You should enter correct settings for connecting with your PostgreSQL database here.
Sample config file.

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'postgres';
$db['default']['password'] = 'postgres';
$db['default']['database'] = 'abc_gis';
$db['default']['dbdriver'] = 'postgre';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['port'] = 5432;
 
2 Comments

Posted by on May 27, 2013 in Codeigniter

 

Tags: