Welcome Guest, Not a member yet? Register   Sign In
Auto-load webpage structure
#1

[eluser]Ci beginner[/eluser]
Hello forum!

I've read the documentation but I didn't find the right way to force to load a default structure in a webpage on every view. I mean, for instance, if I got this structure:

Code:
<html>
<head>
<title>Hi there</title>
[removed][removed]
</head>
<body>
(the viewer content)
</body>
</html>

Instead of writing always the same thing in every view, I want to load it automatically. I thought on making a function like do_header() and do_footer() but I don't know if it will be the best way to do it.

And to finish, I'm starting with CI and all I can say for now... it's the best framework I have ever seen: simply, easy, lightweight... long life, CI!

Thank you very much in advance!

Note: the [removed] thing was a "script src" tag but the forum deleted it.
#2

[eluser]John_Betong[/eluser]
 
Search the forums for "Partial views"
 
 
 
 
#3

[eluser]Ci beginner[/eluser]
[quote author="John_Betong" date="1248674769"] 
Search the forums for "Partial views"
 
 
 
 [/quote]

Nice, I found something. I probably make a library/helper/something with do_header() and do_footer(), put in autoload and then, call it from views.

Thank you!
#4

[eluser]InsiteFX[/eluser]
Hi,

You need to create different views for the html web page.

header_view.php
content_view.php
footer_view.php

these shoud be in your CodeIgniter application views folder.

then in your html web page add tese views to it.

And this is how you pass data to your view.
Code:
<?php
/**
* Home Class
*
* @package        Package Name
* @subpackage    Subpackage
* @category    Category
* @author        Author Name
* @link        http://example.com
*/

class Home extends Controller {
    
    function __construct()
    {
        parent::Controller();
    }
    

    function index()
    {
        $data['mytitle']    = "Pro Covers FX CMS";
        $data['mytext']        = "This website helps you to keep track of the other websites you control.";
        $data['myrobots']    = 'name="robots" content="noindex, nofollow"';
        
        $data['mywebtitle']    = 'Web testing';
        $data['base']        = $this->config->item('base_url');
        $data['css']        = $this->config->item('css');
        
        $data['copyright']    = $this->config->item('copyright');
        $data['year']        = date("Y");
        $data['copyend']    = $this->config->item('copyend');

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

}

/* End of file home.php */
/* Location: ../application/controllers/home.php */

html you will add these were they belong

Code:
<?php $this->load->view('header_view'); ?>
<?php $this->load->view('content_view'); ?>
<?php $this->load->view('footer_view'); ?>

Hope this helps.

Enjoy
InsiteFX
#5

[eluser]Ci beginner[/eluser]
[quote author="InsiteFX" date="1248683356"]Hi,

You need to create different views for the html web page.

header_view.php
content_view.php
footer_view.php

these shoud be in your CodeIgniter application views folder.

then in your html web page add tese views to it.

And this is how you pass data to your view.
Code:
<?php
/**
* Home Class
*
* @package        Package Name
* @subpackage    Subpackage
* @category    Category
* @author        Author Name
* @link        http://example.com
*/

class Home extends Controller {
    
    function __construct()
    {
        parent::Controller();
    }
    

    function index()
    {
        $data['mytitle']    = "Pro Covers FX CMS";
        $data['mytext']        = "This website helps you to keep track of the other websites you control.";
        $data['myrobots']    = 'name="robots" content="noindex, nofollow"';
        
        $data['mywebtitle']    = 'Web testing';
        $data['base']        = $this->config->item('base_url');
        $data['css']        = $this->config->item('css');
        
        $data['copyright']    = $this->config->item('copyright');
        $data['year']        = date("Y");
        $data['copyend']    = $this->config->item('copyend');

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

}

/* End of file home.php */
/* Location: ../application/controllers/home.php */

html you will add these were they belong

Code:
<?php $this->load->view('header_view'); ?>
<?php $this->load->view('content_view'); ?>
<?php $this->load->view('footer_view'); ?>

Hope this helps.

Enjoy
InsiteFX
[/quote]

I didn't fully understand but I'll try it, thank you very much! Smile
#6

[eluser]wowdezign[/eluser]
This thread has an explanation of how to do a simple type of templating.

http://ellislab.com/forums/viewthread/124268/
#7

[eluser]Ci beginner[/eluser]
[quote author="wowdezign" date="1248712500"]This thread has an explanation of how to do a simple type of templating.

http://ellislab.com/forums/viewthread/124268/[/quote]

I'm very grateful, thank you, really! This helps me a lot. That was the thread I wanted :-)
#8

[eluser]Ci beginner[/eluser]
Hey guys! I noticed that using "hooks" is the best way to make this - well, maybe not the best, but the easier.

But I have a little issue, how to put a title for every view? I mean, the hooks let me call any function from a class in different times (before loading the controller, after, when the page is loaded and sent...), but I'm unable to send the right title for the header.

Any ideas? Thank you!
#9

[eluser]InsiteFX[/eluser]
Ci beginner,

If you look at the code I posted above it will show how to set the title in your views.

Look at the index function/method $data

Enjoy
InsiteFX
#10

[eluser]wowdezign[/eluser]
[quote author="Ci beginner" date="1248807583"]But I have a little issue, how to put a title for every view?[/quote]

Do mean that you need to know how to do it with hooks or the way we were describing?




Theme © iAndrew 2016 - Forum software by © MyBB