Showing posts with label Advanced Layout Library. Show all posts
Showing posts with label Advanced Layout Library. Show all posts

Wednesday, July 14, 2010

Codeigniter Advanced Layout Library

We have several layout library in the wiki of codeigniter. But those has only one replacement block. Advanced codeigniter library solves this problem. You can find the features of advanced layout library here here. Let's discuss about Advanced Layout library for codeigniter.

we will see every code block of the library and discuss them seperately. At first we have defined our necessary variables.

#ci instance
    public $ci;
    #layout variable
    public $layout;

In the constructor function we have created an instance of codeigniter. the argument of the function gets the filename of our main codeigniter library.

/**
     * Constructor
     *
     * @author Tahsin Hasan 
     * @return void
     * @param  layout String layout file name
     * @access public
     */
    public function __construct($layout = "layout_main") {
        $this->ci =& get_instance();
        $this->layout = $layout;        
    }
Let's see the code block of the function that handles the block replacement of our layout. we are passing here three arguments: blocks array contains key-value relationship of block and their corresponding replacement code chunk. view is the filename of the main body content area.
/**
     * shows our blocks in the layout section
     *
     * @author Tahsin Hasan 
     * @return void
     * @param  blocks Array blocks to replace
     * @param  view String code to replace with
     * @param  data Array the data we need to pass
     * @access public
     */
    public function view($blocks, $view, $data)
    {   
        $layout       = $this->layout;
        $data['content_for_layout'] = $this->ci->load->view($view, $data, true);
        
        $view = $this->ci->load->view($layout, $data, true);
        foreach($blocks as $key=>$val)
        {
           if(empty($val))
           {
               $replaces[$key] = '';
           }
           else
           {
               $replaces[$key] = $this->ci->load->view ( $val, NULL, TRUE );
           }            
        }
        $view = str_replace(array_keys($replaces), array_values($replaces), $view);
        
        $this->ci->load->view ( 'view', array ('view' => $view) );
    }

The content_for_layout variable contains the main body section of a page. We replace this string value with our page specific content. with this page specific content, we then replace the layout with our values and store it in the view file.

Download Advanced Layout library from here.
The block variable contains the other replacements except the main content. we replace each varible with the foreach loop.

the str_replace function done the tricks here. it replaces the keys with the values of the view variable. And finally, we load the view file.

Download Advanced Layout library from here.


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Features of Advanced Layout library of Codeigniter

We have seen the documentation of Advanced Layout Library of Codeigniter. But before using it, we must know what features it brings to us. Let's see them:

  • Other layout library give us the opportunity to make one single block replacement for our layout. But in Advanced Layout library, we can have as many blocks as we wish to have. We just have to define the block and a variable to represent it. Advanced Layout library will take care of the rest. it's simple.
  • We can even have multiple blocks in our main content block. we have shown how to use multiple blocks in layout and also in the main content block. So, we will have more control of your layout using Advanced Layout library for codeigniter.

Download Advanced Layout library from here.


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

How to use Advanced layout library

We have seen the documentation. Now let's see how we can use the library. At first we need to load Advanced Layout Library for codeigniter.

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

Now we will set our main layout file in it:

$this->advancedlayout->setLayout('path_to_layoutfile');

We have put our main layout file in the view file. The file is like this:


html xmlns="http://www.w3.org/1999/xhtml"
    head
//        stylesheets link will be here.
        
    /head
    body
        {HEADER_LAYOUT}
        
        
{FLASH_MSG_CONT}
{FOOTER_LAYOUT} /body /html

Here, you can see we have set some variable which will be replaced with our layout values. We can have here as many replacement block as we like. we have set header, top navigation, flash message, body and footer. Not necessary that we also need to implement all those blocks. just use as you like the blocks to be.

In the controller, from which the page is called, we need to replace our layout variables there. the following code does the trick:

$this->advancedlayout->view(array ('{HEADER_LAYOUT}' => 'common/header','{TOP_LAYOUT}'=>'', '{FLASH_MSG_CONT}' => 'common/flash_msg_cont', '{FOOTER_LAYOUT}' => 'common/footer' ),$viewName, $this->_data);

Here, you can see that each variables is set as key and there is a corresponding files in he view file. so, we just write the location of the specific view file. then the variable is replaced with our code.

we set multiple blocks even the main content block. just check the following code block.

echo $admin_right_column;

we are echoing a variable, this can be any variable that we set in the controller. now we need to write the following the controller:

$this->_data['admin_right_column'] = $this->load->view('common/admin_right',$this->_data, TRUE);

Here, the variable contains the content of the admin right column.

And finally, you need to have a view file named 'view' in our main view folder. the file will be like this:

echo $view;

Download Advanced Layout library from here.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Download Advanced Layout Library for Codeigniter

We have discussed the features, documentation and user guide for Advanced Layout Library for Codeigniter. now Just download it from here. After downloading it:

  • Take the library and drop it under the library folder of Application folder.



See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide