Welcome Guest, Not a member yet? Register   Sign In
Template library of Colin Williams not working [Solved]
#1

[eluser]ajitabhpandey[/eluser]
Hi,

I have recently started using CodeIgnitor for few of my projects. I am using the template library version 1.4.1 from Colin Williams (http://www.williamsconcepts.com/ci/codei.../template/). After following the instruction to place the files in application/config, application/library and application/view, I made the following change in index function of "welcome" controller which comes with the default code ignitor code.

Code:
function index()
    {
        //$this->load->view('welcome_message');
        $this->template->render();
    }

When I visit the URL http://localhost, this is what I get:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$template

Filename: controllers/welcome.php

Line Number: 13

Any hints as to what am I doing wrong.
#2

[eluser]theprodigy[/eluser]
do you have template.php in your config folder, and does it contain the necessary $template array as specified in http://www.williamsconcepts.com/ci/codei...rence.html?
#3

[eluser]ajitabhpandey[/eluser]
Yes I have the following line:

Code:
$template['default']['template'] = 'template';

I have tried adding a php extension as follows, but it did not work as well.

Code:
$template['default']['template'] = 'template.php';
#4

[eluser]steelaz[/eluser]
Looks like Template library is not loaded, try adding this line before using $this->template

Code:
$this->load->library('template');
#5

[eluser]ajitabhpandey[/eluser]
Yep, works like a charm. I thought any libraries put in applications/libraries folder should be loaded automatically. At-least that's what happening in one of the other projects where a custom php file in application/libraries directory is being auto-loaded.

Thanks for pointing that out.
#6

[eluser]steelaz[/eluser]
Most of the time you don't need to use all libraries in a single controller, so I think it's better to load them when you need them. For libraries that you use in most controllers, such as Template, you can auto-load them by editing /application/config/autoload.php




Theme © iAndrew 2016 - Forum software by © MyBB