Welcome Guest, Not a member yet? Register   Sign In
Blog application breakdown...
#1

[eluser]CodeTroll[/eluser]
Hi,

I am trying to develop an application where a blog is a part of it. I am a little baffled as how to best implement what I need so I am turning to the collective braintrust here on the board Smile

Currently I have a controller (blog) that handles both the actual blog entries, as well as the comments for each blog. I also have a model (blog_model) to handle all the DB action.
Both on the actual blog page of the application, as well as in other parts of the application I want to show a list of the latest 5 blog entries. I have a list of blog components that I would like to be able to show in various combinations:

showLatest5BlogEntries (this will be shown on various other pages besides the actual blog pages)
showLatestBlogEntry
showBlogComments (shows blog comments for a specific blog entry)
showAllBlogEntriesThisMonth
showBlogSearchForm (takes year + month as input)
showBlogSearchResults (shows a list of blog entries matching the above criterias)
showBlogEntryForm (this is where the owner enters a new blog entry)
showBlogCommentForm (this is where visitors and owner comments on each blog entry)


On the blog entry page I want to have the following components shown:
Main content area:
showLatestBlogEntry
showBlogComments
showBlogCommentForm

Sidebar area:
showLatest5BlogEntries (clicking on a title here will take the user to a page with the chosen blog entry and the corresponding comments)


On the blog search page:
Main content area:
showAllBlogEntriesThisMonth

Sidebar area:
showBlogSearchForm (takes year + month as input)

On the blog search results page:
Main content area:
showBlogSearchResults (clicking on a title here will take the user to a page with the chosen blog entry and the corresponding comments)

Sidebar area:
showBlogSearchForm (takes year + month as input)


There are more pages of course (blog entry form page ie, but the above covers the main functionality). I am using views, rather than templates, but I am not sure how all this should be broken down into controllers and views?
Would it be a good idea to have a controller for the blogcomments for example? (this would make it possible to have the same url endings for both a blog entry and a blog comment (ie /blog/edit/1, blogcomment/edit/4 etc... )

Any one can point me in the proper direction of how to break things down to accomplish this task?


Thank you for your time Smile
#2

[eluser]jedd[/eluser]
Hi CodeTroll,

Have a read about extending [url="/wiki/MY_Controller"]MY_Controller[/url] in the wiki - much of your repeat view partials (sidebars, etc) can be generated using this approach.

I'd probably try to go for a single controller - Blog - to handle everything. If it gets too unwieldy then I'd split it up - but unwieldy is a matter of taste. For people to comment, do they need to authenticate as well, or are you just doing a captcha (or similar) on comment posting?

To address some of your specifics ...

Within the model I'd have get_latest_entries(), and take a param for how many of the latest you want to grab. That aggregates two of the functions you cited. You could try to bundle comments into that call, using a BOOL as a second param. That would aggregate three functions.

I'd have a get_by_month(), that took month and year - defaulting to current month & year if either was missing. That aggregates another two or three of your functions.

Controller wise - probably show(), search(), comment() (in the verb sense)

In your view you can have a bunch of links that take you to controller/method combos with ready-to-go params (search on current month & year, f.e.)

There's many ways you can approach this stuff - so take the above as just one amongst many, rather than The Way.

Quote:Would it be a good idea to have a controller for the blogcomments for example? (this would make it possible to have the same url endings for both a blog entry and a blog comment (ie /blog/edit/1, blogcomment/edit/4 etc... )

What's your design goal with this last bit?
#3

[eluser]CodeTroll[/eluser]
[quote author="jedd" date="1262297154"]Hi CodeTroll,

Have a read about extending [url="/wiki/MY_Controller"]MY_Controller[/url] in the wiki - much of your repeat view partials (sidebars, etc) can be generated using this approach.
[/quote]
Yes - I have already extended the core controller for other purposes (didn't read your wiki entry before now though Smile)

Quote:I'd probably try to go for a single controller - Blog - to handle everything. If it gets too unwieldy then I'd split it up - but unwieldy is a matter of taste. For people to comment, do they need to authenticate as well, or are you just doing a captcha (or similar) on comment posting?

I would prefer to have it all in one controller as it seems the most logical thing to do (to me at least). We are going to use the application for several different people - some of them wanted people to be able to comment without being logged in, some with mandatory login. There is no captcha or anything
like that planned for now.. We might put that in later though.


Quote:Within the model I'd have get_latest_entries(), and take a param for how many of the latest you want to grab. That aggregates two of the functions you cited. You could try to bundle comments into that call, using a BOOL as a second param. That would aggregate three functions.

I will keep the comments and entries methods seperately in the model and put them together in the blog - generally speaking I prefer my methods to only do a single task.

Quote:I'd have a get_by_month(), that took month and year - defaulting to current month & year if either was missing. That aggregates another two or three of your functions.

That's a good idea - I hadn't taken the string of thoughts that far regarding the search so this I will definately use.

Quote:Controller wise - probably show(), search(), comment() (in the verb sense)

In your view you can have a bunch of links that take you to controller/method combos with ready-to-go params (search on current month & year, f.e.)

Perhaps the biggest problem here is that I seem to get duplicate verbs when I am going to handle both entries and comments in the same controller. The obvious way to solve this is to have a different controller for the comments. But it seems to me that
having both in the same controller is the better way - which just mean I will have to find som proper verbs to handle it Smile

Quote:There's many ways you can approach this stuff - so take the above as just one amongst many, rather than The Way.
Quote:Would it be a good idea to have a controller for the blogcomments for example? (this would make it possible to have the same url endings for both a blog entry and a blog comment (ie /blog/edit/1, blogcomment/edit/4 etc... )

What's your design goal with this last bit?

No specific design goal as such - other than to get the ability to use the same verbs for both editing entries and comments. And don't worry - I won't take the above as The Way... i merely hope to see some light that fits my way Wink

Thank you for your time..
#4

[eluser]jedd[/eluser]
[quote author="CodeTroll" date="1262455164"]
No specific design goal as such - other than to get the ability to use the same verbs for both editing entries and comments.
[/quote]

You could denote the type of object being edited using the first param to the method.

foo/blog/edit/b/27 (edits blog id #27)
foo/blog/edit/c/42 (edit comment id #42)

I'm assuming comments and blogs are in separate tables? If not, then you don't need to differentiate, as you can deduce type from ID#.

If they are, you could have:
Code:
// in controller Blog
function edit ( $type = 'c', $id = 'new' )  {
    if ($id == 'new')
        // it's a new post / comment

I've digressed into a merging of initial post() and subsequent edit() functions there. A matter of taste, but DRY tends to lead you down that path.
#5

[eluser]CodeTroll[/eluser]
Hi Jedd,

thank you.. I still have to get used to use the urls that way - but that could work just fine I think. Will probably split it up internally in the class to have two different methods handling each specific thing. But it would all look almost the same to the users.

And yes - the entries and comments are in a table each.

Thank you for your time Smile




Theme © iAndrew 2016 - Forum software by © MyBB