Flipkart

Showing posts with label CI. Show all posts
Showing posts with label CI. Show all posts

Thursday, August 5, 2010

Codeigniter Layout Library

Create Layout.php in libraries(/application/libraries/Layout.php) folder and copy the below code in the file
< ?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Layout { var $obj; var $layout; function Layout($layout = "layout_main") { $this->obj =& get_instance();
$this->layout = $layout;
}

function setLayout($layout)
{
$this->layout = $layout;
}

function view($view, $data=null, $return=false)
{
$loadedData = array();
$loadedData['content_for_layout'] = $this->obj->load->view($view,$data,true);

if($return)
{
$output = $this->obj->load->view($this->layout, $loadedData, true);
return $output;
}
else
{
$this->obj->load->view($this->layout, $loadedData, false);
}
}
}
? >


Then load your library in your controller

You can use it in two ways. First and obvious is to place the following line in the controller’s constructor function.

$this->load->library('layout', 'layout_main');

The second is by enabling codeIgniter to autoload the library by editing /application/config/autoload.php

$autoload['libraries'] = array('layout');

in your controller you may do this:

$this->layout->view('welcome_message');

Master layout

/application/views/layout_main.php
Your view file must use $content_for_layout. For example:

<html>
<head>
<title><?=$title_for_layout?></title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="/css/main.css" type="text/css" />
</head>
<body>
<div id="pagewidth" >
  <div id="header" ><img src="/images/header.jpg" width="700" height="200"></div>
  <div id="wrapper" class="clearfix" >
    <div id="twocols" class="clearfix">
      <?php echo $content_for_layout?>
    </div>
  </div>
  <div id="footer" > Footer </div>
</div>
</body>
</html>

Wednesday, May 5, 2010

Codeigniter in PHP 5.3

First, here’s how to solve the issue regarding these errors:

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\ci\system\codeigniter\Common.php on line 130

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\ci\system\codeigniter\Common.php on line 136

In index.php in your CI folder replace line 12 “error_reporting(E_ALL);” (without quotes) with this:
error_reporting(E_ALL & ~E_DEPRECATED);” (without quotes)

Then, you’ll probably get an error about a bad URI if you try to run any controlls. It should say something like this: “The URI you submitted has disallowed characters.”


Here’s the solution for that as well. In URI.php which is located in \system\libraries replace line 189:
if ( ! preg_match("|^[".preg_quote($this->config->item
('permitted_uri_chars'))."]+$|i", $str))
” (without quotes and without the line break (it’s all one line)

to read like this:
if ( ! preg_match("|^[".str_replace('\\-', '-', preg_quote ($this->config->item('permitted_uri_chars')))."]+$|i", $str))” again without the quotes.