Welcome Guest, Not a member yet? Register   Sign In
Load table library in the controller ?!?
#1

[eluser]FranckRR[/eluser]
I am trying CI 1.7.2 under Apache 2.2.11 / php 5.3.0

When I use table library, there's a problem (I mean for me it's a problem). I must load the library in the controller to be able to use it in my view ... WEIRD !! ...

I thought that for layers separation sake, I must not declare anything other than models and logic in controller ... doing
$this->load->library('table');
in a controller make all the MVC concept unuseful !

I hope I made a mistake, that you can currently load the table library in a view.

Could anyone confirm that I am wrong ?

Thanks
#2

[eluser]Flemming[/eluser]
I always load libraries inside my controllers (often in the constructor). This is fine for MVC separation!

Anyone disagree?
#3

[eluser]rogierb[/eluser]
Quote:I thought that for layers separation sake, I must not declare anything other than models and logic in controller

I hope your library contains logic:-)

It is common practice to load the library in the controller. The view is only meant for formatting output. So loading something is a view is not really the MVC way.
#4

[eluser]FranckRR[/eluser]
Guys !

You haven't give a careful look to the library I load !
$this->load->library('table') What do I have to do with table in a controller !?!

Just for you to know, I load the 'form' helper in my view and it works fine ... as I expected
#5

[eluser]Maglok[/eluser]
You can always load libraries in the view, it won't throw an error on you. The question is if you want to do it with the MVC model. You can just load it all in the controller and use it in the view regardless those functions are available to you in the view as well then. I load table and form libraries in the controller myself.
#6

[eluser]rogierb[/eluser]
It is beside the point what the library does. Your question was where to load a library.
In MVC it is common practice to load a library in the controller, same with a helper or model.
So most logic will go into a controller.
#7

[eluser]FranckRR[/eluser]
Hum

Let's say. I follow your advices : I load the table in the controller and may be add_row to it ...
In my view, I use the table previously loaded in the controller.
Fine it will work

But what if I don't want to use a table any more, I need to display it in a swf. Instead of only coding a new view (which make sense because this is what I want to be changed) I must change the controller code too because I do not use the table anymore. Of course you can let the code there even if it's not used later (if you agree with that, I will stop arguing and pass mt way elsewhere)

MVC means separating logic, data and representation and not common ways or everybody does that...

If I want to represent my model in the view as a table, only the view must be aware of that ! Thus considering table in the controller already commits me about the representation.
#8

[eluser]├╝berfuzz[/eluser]
Ever heard about arrays..?

Code:
$table_content = array(
     array('first_row_first_column', 'first_row_second_column'),
     array('second_row_first_column', 'second_row_second_column'));
#9

[eluser]Aken[/eluser]
[quote author="FranckRR" date="1259356187"]Hum

Let's say. I follow your advices : I load the table in the controller and may be add_row to it ...
In my view, I use the table previously loaded in the controller.
Fine it will work

But what if I don't want to use a table any more, I need to display it in a swf. Instead of only coding a new view (which make sense because this is what I want to be changed) I must change the controller code too because I do not use the table anymore. Of course you can let the code there even if it's not used later (if you agree with that, I will stop arguing and pass mt way elsewhere)

MVC means separating logic, data and representation and not common ways or everybody does that...

If I want to represent my model in the view as a table, only the view must be aware of that ! Thus considering table in the controller already commits me about the representation.[/quote]
I think everybody's point is that it is typical, and usually recommended to load a library in the controller. However if it suits YOUR application better to load it in a view, then there is no reason why you can't. There is rarely a right or wrong when it comes to programming - technically as long as it works, life is grand. There are just opinions about what is best.




Theme © iAndrew 2016 - Forum software by © MyBB