Codeigniter üzerine Smarty Template Engine Kurulumu
Gönderen : Mustafa İleri
Tarih : March 16 | 09:00
Son Cevap Yazan : Mustafa İleri
Öncelikle application/libraries altına son smarty sürümünü indirin ve konumlandırın.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require "Smarty-2.6.26/libs/Smarty.class.php";
/**
* @file system/application/libraries/Mysmarty.php
*/
class Mysmarty extends Smarty
{
function Mysmarty()
{
$this->Smarty();
$config =& get_config();
// absolute path prevents "template not found" errors
$this->template_dir = (!empty($config['smarty_template_dir']) ? $config['smarty_template_dir']
: BASEPATH . 'application/views/');
$this->compile_dir = (!empty($config['smarty_compile_dir']) ? $config['smarty_compile_dir']
: BASEPATH . 'cache/'); //use CI's cache folder
if (function_exists('site_url')) {
// URL helper required
$this->assign("site_url", site_url()); // so we can get the full path to CI easily
}
}
/**
* @param $resource_name string
* @param $params array holds params that will be passed to the template
* @desc loads the template
*/
function view($resource_name, $params = array()) {
if (strpos($resource_name, '.') === false) {
$resource_name .= '.tpl';
}
if (is_array($params) && count($params)) {
foreach ($params as $key => $value) {
$this->assign($key, $value);
}
}
// check if the template file exists.
if (!is_file($this->template_dir . $resource_name)) {
show_error("template: [$resource_name] cannot be found.");
}
return parent::display($resource_name);
}
} // END class smarty_library
şeklinde Mysmarty.php dosyasını oluşturun.ve aynı yere konumlanıdrın yani application/libraries/ altına .
Sonra config/autoload.php de
$autoload['libraries'] = array('mysmarty');
değişikliğini yapıyoruz ki bu kütüphane otomatik yüklensin.
Örnek kullanım şekli :
$this->mysmarty->assign('test', 'Hello World.');
$this->mysmarty->view('welcome_message');
hocam aşağıdaki hatayı alıyorum endendir acaba
Warning: Smarty error: unable to read resource: "index.tpl" in /home/estoguor/public_html/3/libs/Smarty.class.php on line 1095
Bunun sebebi index.tpl dosyanı okuyamaması muhtemelen. Yüklemek istediğin index.tpl yolunu doğru verdiğinden emin olmalısın...

RSS
E-Bülten