Welcome Guest, Not a member yet? Register   Sign In
forms in my model?
#1

[eluser]ixxalnxxi[/eluser]
Hello All,

In the site I'm developing there is a comment feature. The comment feature will be used over again for different things such as media, articles, blogs, news, etc. I decided to make only one table for comments and then set table and field_id columns so that comments could be inserted for content in different tables.

Now to the question, I am going to be displaying a form for submitting comments and I would rather not rewrite the code for every time I need it (the benefits of OOP, right?). My plan was to put the form display function in my comments model because anytime the model is loaded it would be necessary to have the form too. Is this a bad idea? I fear I might be blurring views and models.
#2

[eluser]NogDog[/eluser]
(Caveat: I'm still pretty new to CI.)

An object should focus on one thing. Putting form display into a model object probably does not qualify as such a focus.

I would therfore first consider that it would be its own view if that would work with your design; but if you need to be able to call it from within a view, then I might consider just making it a CI helper function.
#3

[eluser]ixxalnxxi[/eluser]
To make it into a CI helper function, I make a Helper class in the helper directory and just add the function there, correct?
#4

[eluser]NogDog[/eluser]
[quote author="ixxalnxxi" date="1230977995"]To make it into a CI helper function, I make a Helper class in the helper directory and just add the function there, correct?[/quote]
Yes, or alternatively you could extend an existing helper. For instance, if you're already using the HTML helper, you could just create a "MY_html_helper.php" file in your system/application/helpers directory and define the function there. Then when you do your "$this->load->helper('html');", it will include your new function with it.

It may not be a pure OOP solution, but it would seem pretty clean, simple, and efficient to me.




Theme © iAndrew 2016 - Forum software by © MyBB