Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3318130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:40:09+00:00 2026-05-17T22:40:09+00:00

I’ve wrote my own PHP MVC however i’m struggling to distinguish between the model

  • 0

I’ve wrote my own PHP MVC however i’m struggling to distinguish between the model and controller part. For example with a simple form that will add data to the database, the controller is pulling the form data from a request object, and passing it to the Model to handle the actual database insert. However there seems a lot of somewhat duplicate code in here, would it not be simpler to remove the Model part altogether and simply have the controller do the database insert?

I understand that in some cases i may have multiple controllers using the same Model action, however for the occasioanl time this happens it doesn’t seem worth all the extra coding required to constantly seperate the Model and controller?

It’s not so much duplicate code more that it seems a long winded way of doing things as i’m writing a lot of code for what is essentially a simple function, if that makes sense?

Sample code from controller

// processes the new site data
public function add_new_process() {
    // execute action in model
    $Model_Websites = new Model_Websites();
    $name           = $this->request->getPropertyFiltered('sitename',array('sanitize'));
    $descrip        = $this->request->getPropertyFiltered('descrip',array('sanitize'));
    $url                = $this->request->getPropertyFiltered('siteurl',array('sanitize'));
    $signup_url = $this->request->getPropertyFiltered('signupurl',array('sanitize'));
    $acct_id    = $this->request->getPropertyFiltered('acct_id',array('sanitize'));
    $thumbnail  = $this->request->getPropertyFiltered('thumb',array('sanitize'));
    if($Model_Websites->addNewSite($name,$descrip,$url,$signup_url,$acct_id,$thumbnail)) {
        $this->request->addFeedback("Your new website has been added succesfully!");
        $this->request->setFeedbackStatus(true);
        $this->request->storeFeedbackInSession();
        $this->template->redirectBrowser(__SITE_URL.'/websites/');
    } else {
        $this->template->setProperty('page_title', Registry::getConfig('site_name').' :: Add New Website' );
        $this->template->render('websites','show_form'); // controller,view
    }
}

Sample code from Model

function addNewSite($name,$descrip,$url,$signup_url,$acct_id,$thumbnail) {
    $pdo = ConnectionFactory::instance()->getConnection();
    $stmt = $pdo->prepare("INSERT INTO {$this->db_table_websites} SET 
                name = :name
            , descrip = :descrip
            , url = :url
            , signup_url = :signup_url
            , acct_id = :ccbill_site_id
            , thumbnail = :thumbnail
            ");
    $stmt->bindParam(':name', $name, PDO::PARAM_STR);
    $stmt->bindParam(':descrip', $descrip, PDO::PARAM_STR);
    $stmt->bindParam(':url', $url, PDO::PARAM_STR);
    $stmt->bindParam(':signup_url', $signup_url, PDO::PARAM_STR);
    $stmt->bindParam(':acct_id', $acct_id, PDO::PARAM_STR);
    $stmt->bindParam(':thumbnail', $thumbnail, PDO::PARAM_STR);
    if($stmt->execute()) return true;
        else return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:40:09+00:00Added an answer on May 17, 2026 at 10:40 pm

    Well, the question is whether you do want to use MVC or not. If you want to use MVC, then you should not put business logic into the controller, because that’s not where it should be. Please go through

    • In MVC, where do you draw the line between a controller and model? and
    • Fat models, skinny controllers and the MVC design pattern.

    However, no one forces you use MVC. It’s a common pattern and it is good practise to use it when you want to create a maintainable application. Especially the separation of business logic and presentation layer make it worth considering. But with small applications and websites, chances are MVC is oversized. You could just as well structure your site with a bunch of Transaction scripts, where each script handles a single request from the UI. Check out

    • Rasmus Lerdorf’s The No Framework Framework

    for a possible alternate approach.


    As for your code, I dont think it’s overcomplicating things. It probably looks just like it was, because of the verbose code. You could streamline it a bit by creating a FilterChain (alternative) that sanitizes all input transparently before your controller is called. And you could make your form use grouping so you can just pass $form['site'] to your Model with the other values being subkeys of that. Also, you are doing three calls to set the feedback that could probably be handled in one call. Maybe you could write a Feedback Helper to do the three calls for you, but that only exposes one method and does the remaining work internally (or make it accept three arguments or whatever is necessary to cut down on the work needed to add a feedback message).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.