• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI smarty templating with HMVC ?

#1
[eluser]pedma[/eluser]
Hi,

I'm new to CI. It's greate, thanks to all of you, especially the developer.
I'm using CI 2.0.2 & smarty 3 templating scripts : http://ilikekillnerds.com/2010/11/using-...i-library/

It works great. CI 2.0.2 works also well with HMVC : https://bitbucket.org/wiredesignz/codeig.../wiki/Home

We can combine both, but smarty will get only the last entry of $config['template_directory'] in the config file .../application/config/smarty.php

So, if I put like this to .../config/smarty.php config file :
$config['template_directory'] = APPPATH."modules/smartytest/views/";
$config['template_directory'] = APPPATH."modules/mytest/views/";
The library will call only the last one. And give error for the first one.

I think it will work fine, if the Smarty library : Smarty.php (.../application/libraries/Smarty.php) can define which template_directory is the right path for calling the view.

I think we can use array for this, but I don't know how to do it. Any idea ? Please help.

Thank you very much.
-pedma-
pedmajungne@gmail.com

=============================================================================
The config file : .../config/smarty.php is like this :

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$config['template_directory'] = APPPATH."modules/mytest/views/";
$config['compile_directory'] = APPPATH."cache/smarty/compiled";

... etc ...


The library file : ..../libraries/Smarty.php is like this :

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."third_party/Smarty/Smarty.class.php";
class CI_Smarty extends Smarty {

public function __construct()
{
parent::__construct();

// Store the Codeigniter super global instance... whatever
$CI = get_instance();

$CI->load->config('smarty');

$this->template_dir = config_item('template_directory');

$this->compile_dir = config_item('compile_directory');
$this->cache_dir = config_item('cache_directory');
$this->config_dir = config_item('config_directory');
$this->template_ext = config_item('template_ext');
$this->exception_handler = null;

// Add all helpers to plugins_dir
$helpers = glob(APPPATH . 'helpers/', GLOB_ONLYDIR | GLOB_MARK);

foreach ($helpers as $helper)
{
$this->plugins_dir[] = $helper;
}
// Should let us access Codeigniter stuff in views
$this->assign("this", $CI);
}

}

#2
[eluser]Aken[/eluser]
That's because you're only setting the value of a single variable. First you're setting it to one path, then you're changing it to another.

You will have to extend the way Smarty checks directories for files if you want it to check multiple folders. That's not really recommended anyway because what if you have two template files, in different folders, with the same name? What if you want one called, but because of the order Smarty checks, the other is pulled first?

#3
[eluser]pedma[/eluser]
[quote author="Aken" date="1311165254"]That's because you're only setting the value of a single variable. First you're setting it to one path, then you're changing it to another.

You will have to extend the way Smarty checks directories for files if you want it to check multiple folders. That's not really recommended anyway because what if you have two template files, in different folders, with the same name? What if you want one called, but because of the order Smarty checks, the other is pulled first?[/quote]

Hi Aken,

Thank you for your reply. I want to split CI application like this (it's possible using HMVC) :
.../application/modules/accounting
|-controllers/accounting.php
|-models/accountingModel.php
|-views/accounting.php

.../application/modules/purchasing
|-controllers/purchasing.php
|-models/purchasingModel.php
|-views/purchasing.php

So, we can have a separate Template for accounting user & purchasing user, after they login (because of using HMVC, so each module has separate views).

This can be done using another template engine like Phil's Sturgeon template library ?
I can't find STEP BY STEP tutorial how to make Phil's library to work, even without HMVC ... Sad

Then I need ACL to controll that purchasing user can only access 'purchasing' directory & accounting user can only access 'accounting' directory.

Any idea ?

Thanks
-pedma-


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.