Showing posts with label codeigniter. Show all posts
Showing posts with label codeigniter. Show all posts

Friday, 9 September 2016

Compress HTML output in Codeigniter


Compress HTML output



Hello friends today i'm sharing code of compress html output in codeIgniter.
To remove useless white spaces and extra stuff from generated HTML, except for JS.

      Step 1 : Add the compress hook in config/hooks.php

$config['enable_hooks'] = TRUE;
   Step 2 : Add in compress hook to config/hooks.php
$hook['display_override'][] = array(
    'class' => '',
    'function' => 'compress',
    'filename' => 'compress.php',
    'filepath' => 'hooks'
);
Step 3 :  define 'display_override' 
<?php  if( ! defined('BASEPATH'))exit('No direct script access allowed');
function compress()
{
    ini_set("pcre.recursion_limit", "16777");
    $CI =& get_instance();
    $buffer = $CI->output->get_output();

    $re = '%# Collapse whitespace everywhere but in blacklisted elements.
        (?>             # Match all whitespans other than single space.
          [^\S ]\s*     # Either one [\t\r\n\f\v] and zero or more ws,
        | \s{2,}        # or two or more consecutive-any-whitespace.
        ) # Note: The remaining regex consumes no text at all...
        (?=             # Ensure we are not in a blacklist tag.
          [^<]*+        # Either zero or more non-"<" {normal*}
          (?:           # Begin {(special normal*)*} construct
            <           # or a < starting a non-blacklist tag.
            (?!/?(?:textarea|pre|script)\b)
            [^<]*+      # more non-"<" {normal*}
          )*+           # Finish "unrolling-the-loop"
          (?:           # Begin alternation group.
            <           # Either a blacklist start tag.
            (?>textarea|pre|script)\b
          | \z          # or end of file.
          )             # End alternation group.
        )  # If we made it here, we are not in a blacklist tag.
        %Six';

    $new_buffer = preg_replace($re, " ", $buffer);

    // We are going to check if processing has working
    if ($new_buffer === null)
    {
        $new_buffer = $buffer;
    }

    $CI->output->set_output($new_buffer);
    $CI->output->_display();
}
/* Location: ./system/application/hooks/compress.php */

Reference By : Jérôme Jaglale
ENJOY : )   
By :-  RAJA MAHIYARIYA MAHER(tHuNdEr^fR0G)

Thursday, 14 July 2016

Top 3 useful tricks of CodeIgniter



Hi all of you, today i'll share you some codeigniter top tricks.

1 there is an optional perameter in $this->uri->segment

                          when you see http://website.com/controller/method/perameter vs http://website.com/controller/method/ in action ? that time we use that type of code.....
$variable = $this->uri->segment(3)                                                                                                       
there are an optional second one peraemeter that permits set your default value
$variable = $this->uri->segment(3,'SecondPerameter')                                                                      

2 Codeigniter View can return as data with a third perameter
$variable = $this->load->view('viewpage',$data,TRUE);                                                                      
$PDF = build_pdf($page);                                                                                                                         

3 Every Library can have a configuration file
              I can try to keep my library configuration option out of my controllers where possible. suddenly codeigniter lets us seamlessly move that information into application/config widout missing any steps,you need to name your configuration file the same as the library and you are set that,this is the simple example for email library.here is the application/config/email,php file include in every bit of code which one is distibutes

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');                                              
$config['protocol'] = '****';                                                                                                                          
$config['smtp_host'] = '*****************';                                                                                           
$config['smtp_user'] = 'username';                                                                                                             
$config['smtp_pass'] = 'password';                                                                                                              
$config['smtp_port'] = '80';                                                                                                                            
?>                                                                                                                                                                       

if the third pareameter allows you to suppress errors in the event that config file done not exist
$this->config->load('blog_settings', FALSE, TRUE);                                                                                     

ENJOY : )   
By :-  RAJA MAHIYARIYA MAHER(tHuNdEr^fR0G)

Sunday, 20 March 2016

Pagination with CodeIgniter and Bootstrap


Pagination in CodeIgniter with use of codeigniter pagination library and bootstrap

Step 1 : create a file in your CodeIgniter controller folder.
home.php

<?php
class Home extends CI_Controller {
    function __construct() {

        parent::__construct();

        $this->load->model('Citymodel');

        $this->load->library('pagination');

    }
    public function pagination($Starting=0) {
        $config['base_url'] = base_url().'Home/pagination/';
        $TotalRows = $this->Citymodel->record_count();
        $config['total_rows'] = $TotalRows;
        $config['per_page'] = 6; 
        $config['num_links'] = 5;
        $TotalRecord = $config['per_page'];
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['first_link'] = false;
        $config['last_link'] = false;
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo';
        $config['prev_tag_open'] = '<li class="prev">';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $this->pagination->initialize($config); 
        $data['Links'] = $this->pagination->create_links();
        $data['result'] = $this->Citymodel->fetch_data($Starting,$TotalRecord);
        $this->load->view('pagination',$data);
    }
}
?>

Step 2 : Create a file in model folder of CodeIgniter.
Citymodel.php

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Citymodel extends CI_Model {
    function __construct() {
        parent::__construct();
    }
    public function record_count() {
        return $this->db->count_all("area");
    }
    public function fetch_data($Starting,$TotalRecord) {
        $query = $this->db->query("select * from area limit $Starting,$TotalRecord");
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
    }
}
?>

Step 3 : create file in view folder for display records of database
pagination.php

<html>
    <head>
        <title>Codelgniter pagination</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" ></script>
    </head>
    <body>
        <div class="row">
            <div class="col-md-6 col-md-offset-3">
                <h2 class="text-info">User List</h2>
                <table class="table table-hover">
                    <tbody>
                        <tr>
                            <th>Area Name</th>
                            <th>City</th>
                        </tr>
                     <?php
                        // Show data
                        foreach ($result as $result) {
                     ?>
                            <tr>
                                <td><?php echo $result->AreaName ?></td>
                                <td><?php echo "Ahmedabad" ?></td>
                            </tr>
                    <?php } ?>
                    </tbody>
                </table>
                    <?php echo $Links; ?>
            </div>
        </div>
    </body>
</html>

Step 4 : create database and add this table data 
table name - area

CREATE TABLE `area` (`id` int(11) NOT NULL,`AreaName` varchar(100) NOT NULL)
INSERT INTO `area` (`id`, `AreaName`) VALUES (14, 'Bapu Nagar'),(18, 'Prahlad Nagar'),(19, 'C.G. Road'),(20, 'S.G. Road'),(21, 'Navrangpura'),(22, 'Vastrapur'),(23, 'Ashram Road'),(24, 'Paldi'),(25, 'Saraspur'),(26, 'Satellite Area'),(27, 'Sarangpur Darwaza'),(28,'Ambawadi'),(29, 'Ellis Bridge'),(30, 'Ghatlodia'),(31, 'Gulbai Tekra'),(32, 'Gita Mandir Road')(33, 'Mem Nagar'),(34, 'Naranpura'),(35, 'University Area');


NOTE : base url must be like = 'localhost/CodeIgniteProjectName/Home/pagination'

Prompt Web Solution. Powered by Blogger.