Welcome Guest, Not a member yet? Register   Sign In
Models and HTML
#1

[eluser]breaddes[/eluser]
The CodeIgniter wiki describes under the MVC section that models never ever spit out HTML. I am not absolutly clear about that point. I done a navigation model, calling the mainnavigation by a regular mysql statement. It also does the visual output directly by writing a <ul> html-list. That output will be returned to my controller.

Anyway I thought I was an amazing idea. I can reuse my navigation many times, just by calling the models function. This function also gets parameters about the current page which causes an automatic highlighting of the correct bred-crumb-trail.

After reading the wiki I am a bit confused about that idea. What didn't I understand about MVC?
#2

[eluser]Phil Sturgeon[/eluser]
This sounds like some good code and im sure it has saved you a great deal of time, however its not exactly the way MVC is meant to work.

The architecture (therefore this framework) will not stop you doing anything, nor force you to do things in a certain way. I could include database calls right in my view, I could put config settings in my lang files, I could even put all of my CSS in a model file.

Going by that principle, I could have sex with my sister, but as with MVC, we stick to whats right, not whats possible.
#3

[eluser]breaddes[/eluser]
thanks for your reply!
If I'd like to do it in a correct way, how would my example look like? How would I reuse my navgation-html?
#4

[eluser]CI Lee[/eluser]
Quote:Going by that principle, I could have sex with my sister, but as with MVC, we stick to whats right, not whats possible.


... Pass



For the sake of the moral compass of this forum, I will leave that one alone.

-Lee
#5

[eluser]Phil Sturgeon[/eluser]
This is one of the most talked about subjects on the site. You are basically talking about Stem Views.

The idea is to make one view with the navigation HTML, call that then insert it into your main view.

Code:
&lt;?php
class Example extends Controller {

$data['navigation'] = $this->load->view('navigation', $data, TRUE);

$this->load->view('page_name', $data);
}

This all sounds like alot of hassle until you make yourself a simple templating library or helper. You will probably find Coolfactors View Library useful, or give mine a go.
#6

[eluser]Référencement Google[/eluser]
Quote:or give mine a go.

Interresting, can you post some exemples of use of your class?
#7

[eluser]Phil Sturgeon[/eluser]
Code:
// Simple useage
$this->template->title('Something');
$this->template->create('viewname', $data);

// HTML Mode
$this->template->html_mode(true);
$this->template->create('<p>Hello World</p>');

// Wrap Mode Off - ignores the layout file and just calls the view you select.
$this->template->wrap_mode(false);
$this->template->create('pagename', $data);

// Automatic Title Creation
// Uses module name (failing that as most dont use it, class name) then method name using Humanize()
// Eg: blogs/my_blog would give you "Blogs > My Blog"
$this->template->create('something', $data);

// Breadcrumbs
// Automatically includes the module name (you should change this to class name)
$this->template->crumb('My Blog', 'blogs/my_blog');
$this->template->crumb('This Blog Entry');
$this->template->create('something', $data);

// Extra head
$this->template->extra_head('&lt;meta name="keywords" content="bla, bla, bla " /&gt;');

// Extra Head combines well with my asset helper
$this->template->extra_head( css_asset('blog.css') );

This template lib was heavily modified recently from a simple one based on directories to an advanced lib based on Zack's Modular Seperation, but with small changes (remove everything to do with modules) it can easily work without this.

You need the variables demonstrated in this example layout.php
#8

[eluser]Référencement Google[/eluser]
Ok, thank you I will try it




Theme © iAndrew 2016 - Forum software by © MyBB