How to make a sliced layout using the codeigniter framework?

Asked

Viewed 565 times

0

I’m trying to create a system CRUD using the basic codeigniter, where the page header and footer remain fixed and the content dynamic, but I have no idea how to do that. Someone can help me?

  • Speak brother, take a look http://flaviosilveira.com/2010/habilitando-layouts-no-codeigniter-template-engine-1/ I believe it will help you.

1 answer

1


create a view as index

view_index.php

<?php 
$this->load->view('includes/header');//INCLUI A VIEW DENTRO DA PASTA VIEW/INCLUDE/HEADER.PHP
$this->load->view('includes/menu');//INCLUI A VIEW DENTRO DA PASTA VIEW/INCLUDE/MENU.PHP
if($tela != '') $this->load->view('telas/'.$tela);//VERIFICA SE FOI PASSADA A VIEW PELO CONTROLLER SE NÃO ELE USA O CONTROLLER INDEX COMO PADRÃO
$this->load->view('includes/footer');//INCLUI A VIEW DENTRO DA PASTA VIEW/INCLUDE/FOOTER.PHP

Then you just pass the data through the controller that pulls the view according to each function you create and pass the view name to the $data variable

crud.php

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

class Crud extends CI_Controller {
    //CONSTRUCTOR
    public function __construct(){
    parent::__construct();//CHAMA O CONSTRUTOR DA CLASSE PAI
    $this->load->helper('url');//CARREGA O HELPER
}

public function index(){
    //$this->load->helper('url'); CARREGA APENAS PARA A FUNÇÃO
    $dados  =   array(
        'titulo'    =>  'Crud com CodeIgniter',
        'tela'      =>  '',
    );
    $this->load->view('crud',$dados);
}

//TELAS
public function create(){
    $dados  =   array(
        'tela'      =>  'nome_da_view'
    );
    $this->load->view('crud',$dados);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.