Welcome Guest, Not a member yet? Register   Sign In
Code Igniter noob :)
#1

[eluser]Mr. Gibon[/eluser]
Hello all!

I wonder if you could help me. I'm consider building website based on Codeigniter, but after 2 weeks of research and tutorials of Jeffrey Way ( great job Wink ) cannot find solution (example) of dinamic template version.

What I want to get is header,footer, and other additional parts of web contain info form database.

I'm not sure if havin one controller and tons of functions for everypage is the idea of CI, same as loading lots of same things every other controller (if singel controller is a single page).

If you may share with any structure, or existing template tell me yours thoughts about it.


Thanks!
#2

[eluser]Total Shop UK[/eluser]
Hey,

I used HMVC to resolve the problem.

Controller
application > modules > _main > controllers > _main.php

Views
application > modules > _main > views > _top.php
application > modules > _main > views > _bottom.php

You can download my code here http://sourceforge.net/projects/totalshopuk/files/

HMVC http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/
#3

[eluser]JanDoToDo[/eluser]
You want to extend the controller and then put the code to get sutff for header footer etc in that instead of the actual controller.

i.e. create a file called "MY_Controller" in the libraries folder.

put this in the file
Code:
class MY_Controller extends Controller
{
    public $header;
        public $footer;
    
    function __construct()
    {
        parent::Controller();
                $this -> header = // The header you want to have, e.g. from database or otherwise
        }
}

Then in all of your controllers instead of them having a parent of "Controller" you have a parent of MY_Controller i.e.
Code:
class Home extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
$header = $this -> header; // This gets the varaible you assigned to the header in the my_controller file

    }
// all of the sutff you want to do.
}
This way every single one of your pages has access to the variable $this -> header
#4

[eluser]Mr. Gibon[/eluser]
Thanks for reply,

What solution would you choose for dynamic template?

I mean dynamic meta tags, content as $value form a array or database.

for example different set of colours, banners, meta tags, or even css for mydomain.com/page2

I want the template to be modular and easy to edi evey single module display, and code.

well i'm not expert, and php new for me, but i want to get someting similar to:
Code:
<html>
<head>
<meta autor="$value">
<meta description="$value">
<meta keywords="$value">
<?php echo='$value'; ?>
</head>
<body>

<div id="banner">
&lt;?php include'template/banner.php'; ?&gt;
</div>
<div id="content">
&lt;?php echo='$content'; ?&gt;
</div>
<div id="sidebar">
&lt;?php include'template/sidebar.php'; ?&gt;
</div>

<div id="footer">
&lt;?php include'template/footer.php'; ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;
( including jquery, ajax, javascript and so on...)
considering different table in sql for settings of site, and other for contents, and another one for components.


What is the best way to get it in CI without any very advanced solutions?
#5

[eluser]Phil Sturgeon[/eluser]
Modular Extensions is no longer supported, and I am pretty sure your MY_Controller methods will just confuse the man for now.

Use Modular Separation if you want any sort of HMVC system, and I would recommend my Template library to handle your layouts. It's a very simple solution with lots of power available.
#6

[eluser]Total Shop UK[/eluser]
[quote author="Mr. Gibon" date="1271878330"]Thanks for reply,

What solution would you choose for dynamic template?

I mean dynamic meta tags, content as $value form a array or database.
[/quote]

If you check out my code at SourceForge you can see the full code but the below snippets show you how it works..

application/views/home.php
Code:
&lt;?php if (!isset($meta)) $meta=''; echo modules::run('_main/top',$meta); ?&gt;

application/modules/controllers/_main.php
Code:
if ($meta!=''){
      $data['meta']['description']=$meta['description'];
      $data['meta']['keywords']=$meta['keywords'];
}else{
      $data['content'] = $this->content->get_content('home');
      $data['meta']['description']=$data['content']['description'];
      $data['meta']['keywords']=$data['content']['keywords'];
}
$this->load->view('_top.php', $data);

application/modules/views/_top.php
Code:
&lt;meta name="description" content="&lt;?php echo $meta['description']; ?&gt;"&gt;
&lt;meta name="keywords" content="&lt;?php echo $meta['keywords']; ?&gt;"&gt;
#7

[eluser]Phil Sturgeon[/eluser]
Case and point.

Surely:

Code:
$this->template->title( 'Title' )        
            ->set_metadata('keywords', 'keywords, stuff' )
            ->set_metadata('description', 'really easy template library' )
            ->build('page', $data);

Is much nicer syntax, and does not break MVC patterns as much as Modular Extensions?
#8

[eluser]Total Shop UK[/eluser]
I think I'll research Modular Separation as I agree it does look much better, I just always used Modular Extensions because they worked for me.
#9

[eluser]Mr. Gibon[/eluser]
totalshopuk, please give me link to your sourceforge.

Template liblary is a bit too advancet for me, i'm starting my advernture with php/ci.

Can you show me your solutions?

All tuts on the web are showing how to create single pages, functions, controllers, but i haven't found anything how to create dynamic website with adminstration panel with dynamic template.

I'm looking for smothing simple scalable, and secure Smile
#10

[eluser]Total Shop UK[/eluser]
SF - http://sourceforge.net/projects/totalshopuk/files/

I use the code in my eCommerce project as a basis for all my web apps.
By just stripping out the code I don't need and adding additional.

As it uses HMVC, Ajax, CMS etc.. I can use it for all sorts of development work.

Let me know if you need any additional help.




Theme © iAndrew 2016 - Forum software by © MyBB