Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    76
    Thanks
    61
    Thanked 0 Times in 0 Posts

    Dynamic controller in MVC?

    Hello. I have built myself a basic MVC system and it's working well. I have a problem though in the fact I run several websites and I want to use this framework for all my websites.

    Now in my controller I create lots of methods and create a new instance in each. This then loads the required model and grabs that models methods as needed like so

    PHP Code:
    class controller {

    public function 
    Stories() {
    //Takes the following from Stories.class model
    $new = new Stories();
    $new->setStories();
    $new->getStories();
    }

    public function 
    Search() {
    //Takes the following from Search.class model
    $new = new Search();
    $new->setParams();
    $new->getParams();
    }

    // ...and so on as I could have loads of methods in my controller


    Now the controller could become unwieldy if I have a load of methods in here that cover several websites.

    So is the best practice here to have one controller per website and only load the methods needed in each controller or maybe I could somehow generate a controller in MySQL?( ie a table with all of the methods I want to use per website) Or is there a better option here anybody can suggest? Thank you

  • #2
    New Coder
    Join Date
    Dec 2011
    Posts
    61
    Thanks
    4
    Thanked 10 Times in 10 Posts
    If you want the ability to associate categories or tags with pages (or posts), you will need to create a categories (tags) table. Then you would need a create a pages_categories table that will act that would act as the intermediary between the pages/posts and the categories/tags.

    So in short, your on the right track in thinking that you will have to add more tables to the database in order to make your controller more manageable


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •