4 Replies - 794 Views - Last Post: 30 August 2017 - 09:37 AM

#1 harro.rm  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 18-June 16

Best way to organize controller actions and views?

Posted 07 November 2016 - 07:17 PM

I'm not too familiar with the MVC architecture as my web dev related class used node.js and express.js (which isn't exactly MVC), so I'm working on a side project to learn more about it.

The side project I'm working on is currently organized something like this:

view
   |_dashboard
       |_index
   |_addItem
       |_index
   |_removeItem
       |_index
   ...

// As for my controllers they're like this:

class DashboardController {
    index() {
        // render dashboard/index.whatever
    }
}

class AddItemController {
    index() {
        // render addItem/index.whatever
    }

    // more actions
}
...


As you can see, in each controller, there is an index() that renders the page for that controller. But since this is like a dashboard/management system application, would it be better to have all of those index() in the DashboardController instead?

The reason I think this is because the dashboard would have links to each of those sections, then doing it this way, the controllers would only have business logic actions or render actions for specific views just for that controller.

If I do it this way, then would I move each of the index files into the dashboard views folder (of course renaming them)?

Is This A Good Question/Topic? 0
  • +

Replies To: Best way to organize controller actions and views?

#2 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,761
  • Joined: 12-December 12

Re: Best way to organize controller actions and views?

Posted 08 November 2016 - 12:02 AM

As you are not too familiar with MVC then I don't understand how you could be attempting to redesign it, to create your own custom version of it, before you've studied and understood it?

What language are you using? If *.NET then you could start with, for example, an ASP.NET MVC tutorial and work through it to understand how it works and how it is organised. Most languages have available a number of MVC frameworks that you could use as a starting point.

This might be a good start:

A Simple MVC Framework With Node and Express
Was This Post Helpful? 0
  • +
  • -

#3 harro.rm  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 18-June 16

Re: Best way to organize controller actions and views?

Posted 08 November 2016 - 11:13 AM

Oh think you've misunderstood. I'm not trying to redesign anything, I was just asking how the actions should be organized.

In my project, I currently have an index action that renders the main index page for that controller. But the application is sort of like a admin dashboard application, so the dashboard contains all links to other pages. Would it be a good idea to put the index action for each controller into the dashboard controller or leave them in their respective controllers?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,761
  • Joined: 12-December 12

Re: Best way to organize controller actions and views?

Posted 08 November 2016 - 11:49 AM

You still haven't said what language you are using?

In order to study MVC you would be following a tutorial; which tutorial? Does it use a central dashboard?
Was This Post Helpful? 0
  • +
  • -

#5 max_fox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-August 17

Re: Best way to organize controller actions and views?

Posted 30 August 2017 - 09:37 AM

Maybe this article can help you: https://codetiburon....io-js-sails-js/ ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1