Codeigniter - How to install multiple layout templates and assets (css, js and images)?

I use the codeigniter framework for my web project. My question is how to install multiple template templates and the base path for assets like css, js and images? I want to configure the interface, login and rear end. So there are 3 layouts that I need to customize.

My project structure

enter image description here

This is sample code for my project.

MY_Controller.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_Controller extends CI_Controller {
  protected $layout = 'admin';

  protected $stylesheets = array(
    'app.css'
  );
  protected $javascripts = array(
  'app.js'
  );

  protected function render($content) {
    $view_data = array(
      'content' => $content,
      'stylesheets' => $this->get_stylesheets(),
      'javascripts' => $this->get_javascripts()
    );
    $this->load->view($this->layout,$view_data);
  }

  protected function get_stylesheets() {
    return $this->stylesheets;
  }

  protected function get_javascripts() {
    return $this->javascripts;
  }


}

home.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends My_Controller {
  public function index() {
    $content = $this->load->view('home/index',null,true);
    $this->render($content);
  }
}

?>

I found this link on the Internet, but is not suitable for my project. http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html

+3
source share
2 answers

I used this, maybe this sample will help you

(/user.php)

<?php
    class User extends CI_Controller 
    {
        function displayuser()
        {
            $data['users'] = array(1,2,3);
            $data['inc_page'] = 'display'; // views/display.php page
            $this->load->view('user_layout', $data);
        }
    }
?>

(views/display.php)

<table border="0" cellspacing="0" cellpadding="3">
    <?php
        foreach($users as $userid)
        {
    ?>
    <tr>
        <td><?php echo $userid;?></td>
    </tr>
    <?php
        }
    ?>
</table>

(views/user_layout.php)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php echo $this->load->view($inc_page); ?>
</body>
</html>
0

site_url(); css . , "css".

, style.css . site_url.   

0

All Articles