Welcome Guest, Not a member yet? Register   Sign In
File checking
#1

In my view folder I have a theme_view.php

Which checks for multiple views etc and sets the correct theme.

Is this code OK seems to work

PHP Code:
<?php 

$views 
= array(
    
APPPATH 'views/theme/' $this->config->item('config_theme') . '/template/common/header_view.php',
    
APPPATH 'views/theme/' $this->config->item('config_theme') . '/template/' $page '.php',
    
APPPATH 'views/theme/' $this->config->item('config_theme') . '/template/common/footer_view.php',
);

foreach (
$views as $view) {

    if (
file_exists($view)) {
        
$output $view;
        break;
    }
}

if (
$output == TRUE) {
    
    
$this->load->view($this->config->item('config_theme') . '/template/common/header_view');
    
$this->load->view($this->config->item('config_theme') . '/template/' $page);
    
$this->load->view($this->config->item('config_theme') . '/template/common/footer_view');

} else {
    
    
show_error('Your Views ' $view 'Do Not Exists!');
}

?>


And Controller

PHP Code:
<?php

defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends CI_Controller {

    public function 
index()
    {
        
$data['title'] = 'Welcome To Codeigniter';

        
$data['page'] = 'common/home_view';

        
$this->load->view('theme_view'$data);
    
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

(This post was last modified: 07-01-2016, 04:27 AM by PaulD. Edit Reason: Added PS )

It looks fine to me (although I do not like to load views from views), but I would question the need for the file_exists checks, as the loader class does this anyway. You would then only need:

PHP Code:
$this->load->view($this->config->item('config_theme') . '/template/common/header_view');
$this->load->view($this->config->item('config_theme') . '/template/' $page);
$this->load->view($this->config->item('config_theme') . '/template/common/footer_view'); 

Much cleaner!

PS I would put this into a theme library, and call the views from there. The library could then be as complex as you like, coping with theme JS and CSS files for the footers and headers, or more complex theme layouts that require more than a single header and footer. For instance your blog page might need a standard blog_header and blog sidebar, or your login page might need a public_header and public_footer. You could then have a theme config file with different setups for different page styles within a theme.
Reply
#3

(07-01-2016, 04:12 AM)PaulD Wrote: It looks fine to me (although I do not like to load views from views), but I would question the need for the file_exists checks, as the loader class does this anyway. You would then only need:

PHP Code:
$this->load->view($this->config->item('config_theme') . '/template/common/header_view');
$this->load->view($this->config->item('config_theme') . '/template/' $page);
$this->load->view($this->config->item('config_theme') . '/template/common/footer_view'); 

Much cleaner!

PS I would put this into a theme library, and call the views from there. The library could then be as complex as you like, coping with theme JS and CSS files for the footers and headers, or more complex theme layouts that require more than a single header and footer. For instance your blog page might need a standard blog_header and blog sidebar, or your login page might need a public_header and public_footer. You could then have a theme config file with different setups for different page styles within a theme.

Thanks for ideas.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB