Welcome Guest, Not a member yet? Register   Sign In
Newsletter Application
#1

[eluser]huggiebear[/eluser]
I'm creating a newsletter application and it has to have three features:

1. Articles
2. Poll
3. Photo with random caption

All three of these elements have to be on the same page at the same time, so I'll lay it out so that links to the articles are on the left, the main article is in the middle and on the right is the poll and the captions.

Now do I create a single controller called newsletter, with all functions, such as getpollresults(), displaypollresults(), updatepollresults(), addpollquestion(), displayrandomcaption(), addrandomcaption() etc.

Or...

Do I have a separate controller for each, poll, that contains the poll methods, caption that contains the caption methods and display that show's it all.

I'd have thought I need the second option, but if this is the case, will I still be able to display everything on one page? I can only call a single view from a controller right?

Regards
Huggie
#2

[eluser]huggiebear[/eluser]
I was thinking about this again this morning after a sleep and wonder if a better way to go would be to have a display controller, that has the methods such as displaypollresults() and displayrandomcaption() etc, then have an update controller that has updatepoll() addpollquestion() etc.

Any thoughts?

Regards
Huggie
#3

[eluser]dedenf[/eluser]
are making a model for those controller? if so, maybe you can simplify those controller name by seperating the task

my thought:

poll/update
poll/addquestion
poll/result
caption/display

etc
and yes, in my opinion you should separate those controller, but if you want combaine it in one page, you could call the model that do what the page display.
#4

[eluser]huggiebear[/eluser]
OK, I think I get it.

So I can create the following models:

1. Poll - Contains poll methods addquestion(), addanswer(), display(), vote()
2. Caption - Contains caption methods getimage(), getcaption(), add(), display()
3. Article - Contains article methods add(), delete(), display()

Then I have individual controllers, one called maybe Main that loads all of the above models and calls the display() methods, then one for each of the individual components of my newsletter to carry out the other functions.

I have a single view (loaded from Main) that displays my main page with all of my components on it and then lots of other views (containing forms and edit options) for the other components loaded by their individual controllers?

That's how I've intepreted what you've said, how about it?

Regards
Huggie
#5

[eluser]dedenf[/eluser]
sorry for my bad english Big Grin
if i wrote the code, it maybe turns out like this
Code:
<?php
class Main extends Controller{
    function Main(){
        parent::constructor();
        /* other library */
        $this->load->model('poll');
        $this->load->model('article');
        $this->load->model('caption');
    }

    function index(){
        $data['poll'] = $this->poll->display();
        $data['article'] = $this->article->display();
        $data['caption'] = $this->caption->display();
        $this->load->view('my_view',$data);
    }
    
    //$modelname, or anything that contain the poll,article or caption parameter
    function edit($modelname, $rec_id)
    {
        switch($modelname){
            case 'poll':
              $this->poll->edit($rec_id, $value); // or anything
            break;
        .........
        }
    }
    ...........
}
?>
just my thought, maybe the other can give you better suggestions
#6

[eluser]huggiebear[/eluser]
Thanks kompiebutut,

I'm not sure I like the idea of a single controller for all actions of all components, so I'll go with the multiple controller option.

I'll give it a try and see how it turns out, if I get any issues I'll post back here.

Regards
Huggie
#7

[eluser]dedenf[/eluser]
yup, if we separate each controllers, we can make a clean and structured codes
#8

[eluser]tinawina[/eluser]
I'm so glad to have seen his post this morning. Ultimately I'm going to build out a site that has a variety of different components to it -- things like tagging, commenting, ratings, xmlrpc (wh i'm dreading!) -- and will have some authentication stuff and on. Typical site stuff. But have only ever done this type of thing with procedural PHP. I'm digging into figuring out how to fit this all together using CI today and have been puzzling over just how to get started.

Kompiebutut -- thanks for posting your coding approach. I never would have thought to do it like that.

Huggiebear -- it will be great to see your code and structure. I hope you will post what you come up with. And I agree with you -- I would break all out into separate controllers too. I just think that will make maintaining the thing going forward much easier. Keep us posted!
#9

[eluser]huggiebear[/eluser]
tinawina,

I might post all of the code in a zip once complete, depending on how it turns out, if I'm not too keen on it then I won't post it, but I will help out posting answers to questions regarding any issues I have.

Regards
Huggie
#10

[eluser]tinawina[/eluser]
Great! I'm planning to post code too and ask for feedback. This will be an interesting thread moving forward. I think newbies to CI/OOP/MVC - like myself... -- will get a lot out of it.




Theme © iAndrew 2016 - Forum software by © MyBB