Welcome Guest, Not a member yet? Register   Sign In
Newbie MVC question
#1

[eluser]Doug Lerner[/eluser]
In the docs, when describing the calendar class, they give an example:
Code:
$this->load->library('calendar');

echo $this->calendar->generate();

That works fine, but you normally wouldn't want to do that inside the class, would you?

I changed this to:

In the Controller class definition:
Code:
$this->load->library('calendar');
$data['calendar'] = $this->calendar->generate();
$this -> load -> view('blogview', $data);

And in the view file, I added
Code:
<?= $calendar ?>

in an appropriate place.

Am I approaching this the preferred way? Or are people tending to lump everything into the controller?

It seems one nice thing about using a framework like this is that the view file itself is then easy for a designer to modify any way they want without seeing the underlying code. All they need to know are the variables they have access to, right?

Thanks,

doug
#2

[eluser]AgentPhoenix[/eluser]
That's the way I'd do it. No sense in dumping generated code out in the controller; that's what the view is for. Smile
#3

[eluser]xwero[/eluser]
You are right doing it your way. the example is the least amount of code needed to see results but it isn't the correct MVC way.




Theme © iAndrew 2016 - Forum software by © MyBB