Welcome Guest, Not a member yet? Register   Sign In
Creating a custom template controller/library in CodeIgniter
#1

[eluser]Unknown[/eluser]
Really like codeigniter but I would like to implement a template layer to my project. The main reason for this is because the exisiting project has a databased template system which requires quite a bit of logic which may call controllers to insert data into blocks. Each of these would then have their own view as well.

So, i'm trying to think of the best approach. From what I understand, a model isn't the right way and I have been advised to use a library. I've looked at the ones that are currently available and think it would be best to create one from scratch as my template doesn't need that much flexibility.

As an end result, im wanting to be able to call something like $this->load->mytemplate(5,$data,'content-view') and it will deal with the data, insert it into the content-view view and wrap it around template 5s code and views.

Whats the best approach which sticks to mvc methodologies?
#2

[eluser]Otemu[/eluser]
Definitely the best way is to create a library(custom class)
Use $this->CI =& get_instance(); so you have access to other classes
Then to load database use $CI->load->database();
to run queries use $this->CI->db->query()

Should be no problem for you to call something like this within your class structure
$this->template->mytemplate(5,$data,‘content-view’)

Your have a function like this

Code:
function mytemplate($myNum, $data, $myView)
   {
//your code
   }

Look at how Codeigniter writes there core libraries for tips

Hope that helps




Theme © iAndrew 2016 - Forum software by © MyBB