Welcome Guest, Not a member yet? Register   Sign In
Navigation like a site without framework
#11

[eluser]Dyllon[/eluser]
[quote author="brianw1975" date="1265460846"]
...just like most women can have more than one child... a controller can load more than one view.
[/quote]

Although it's true, that is probably the strangest programming comparison I have ever heard.
#12

[eluser]brianw1975[/eluser]
[quote author="Dyllon" date="1265502303"][quote author="brianw1975" date="1265460846"]
...just like most women can have more than one child... a controller can load more than one view.
[/quote]

Although it's true, that is probably the strangest programming comparison I have ever heard.[/quote]

lol, I've got a million of them... that one just popped into my mind when i was writing that post. i usually use a car or home construction metaphor, but none seemed as well suited.

I mean.. i just sounds better than "Home Depot has more than one Drill, so can you" -- know what i mean?
#13

[eluser]Dyllon[/eluser]
just like a garage can house multiple cars, your controllers can load multiple views....
I guess the women have multiple children thing is a little more fitting for the scenario, there's got to be a robot metaphor in here somewhere.
#14

[eluser]Haskabab[/eluser]
I just came across some templating libraries. Is it advisable to use one of those? I'm afraid that if I use one of those now I'll never understand how to do it manually.
#15

[eluser]SpooF[/eluser]
Just going to through this in here:

http://github.com/benedmunds/CodeIgniter-MY_Controller
#16

[eluser]Haskabab[/eluser]
[quote author="SpooF" date="1265510532"]Just going to through this in here:

http://github.com/benedmunds/CodeIgniter-MY_Controller[/quote]

Ehm thanks? What's that Tongue
#17

[eluser]SpooF[/eluser]
Its an extension of the CodeIgniter controller by Ben Edmunds. I mainly use it for my views. The idea behind a MY_Controller is to allow you add anything you want to all your controllers with out copy & pasting it into every single one. If you have a common function you use through out them all, or if you need to set a variable. I mainly posted this for the render function.

Code:
protected function render($template='main') {
        $view_path = $this->controller_name . '/' . $this->action_name . '.tpl.php'; //set the path off the view
        if (file_exists(APPPATH . 'views/' . $view_path)) {
            $this->data['content'] .= $this->load->view($view_path, $this->data, true);  //load the view
        }
        
        $this->load->view("layouts/$template.tpl.php", $this->data);  //load the template
    }

This allows you to have a shell for all your pages, it then will insert based upon the current controller and method/action/function. Your main template is in applications/views/layouts/ by default this is going to be called main.tpl.php. All your other views will be under application/views/[controller_name]/[method/action/function].tpl.php

Then all you have to do is call $this->render() and it does all the template stuff for you. Data is stored in $this->data

Example:

Code:
$this->data['title'] = 'My Page Title';
$this->data['news']  = $news;

$this->render();

This MY_Controller also has some other functionality to it, but you can look into that your self.
#18

[eluser]Haskabab[/eluser]
Thanks a lot for the explanation! I completely understand it now and I've just finished my template system and it's all up and running Big Grin.

Thanks for replying guys ^^
~Nick




Theme © iAndrew 2016 - Forum software by © MyBB