• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Site with different layout structures

#1
[eluser]explores[/eluser]
Hi,
I am new to CI and I am trying to figure out how to setup certain pages to use a different layout, for example some pages will use a one column and others will use a two column structure. Currently I have a layout.php in the libraries folder and its set to read a layout.php in the views folder which works fine but when I try to repeat the process for the other layout I get an error message. I have searched the wiki, forum, guide, and Google but nothing I read seems like the correct solution.

Any help would be great
Thanks

ERROR
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Port::$layout
Filename: controllers/port.php
Line Number: 15

libraries Folder:
File: Layout_one_column
CODE:
Code:
<?php  
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Layout_one_column
{
    
    var $obj;
    var $layout;
    
    
    function Layout($layout = "layout_one_column")
    {
        $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);
        }

        }
}
?>

Controllers Folder:
File: port.php
Code:
Code:
<?php

class Port extends Controller
{
    function Port()
    {
        parent::Controller();
        
        $this->load->helper('url');
    }
    function index()
    {
        $data['title_for_layout'] = "Website Portfolio | Florida Web Design Company | Last 7 Studios";
        $this->load->library('Layout_one_column','layout_one_column');
        $this->layout->view('/port/port_view', $data);
        }

    }
?>

#2
[eluser]danmontgomery[/eluser]
Code:
class Layout_one_column
{
    
    var $obj;
    var $layout;
    
    
    function Layout($layout = "layout_one_column")

I assume function Layout() is intended to be your construct?

Code:
class Layout
{
    ...

    function Layout( ...

Also:

Code:
$this->load->library('Layout','layout_one_column');
$this->layout->view('/port/port_view', $data);

[edit]

Just read that the library is named layout.php, the class name must match the filename.

http://ellislab.com/codeigniter/user-gui...aries.html

Quote:Naming Conventions

* File names must be capitalized. For example: Myclass.php
* Class declarations must be capitalized. For example: class Myclass
* Class names and file names must match.

#3
[eluser]explores[/eluser]
Thanks, I got it working. I didn't have the naming convention correct.

Thank You very much.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.