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

  • Home
  • SEARCH
  • 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 8408317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:35:57+00:00 2026-06-09T23:35:57+00:00

I want to make clear something before i proceed with my project to prevent

  • 0

I want to make clear something before i proceed with my project to prevent bad code practice.
I developed in ruby on rail before and i want to know is it can make it the same like in PHP because im starting learning but i don’t want to use the framework like Zend,Yii,etc

For me,
model is the place where data is insert to the database.

controller is the place that find all the parameters and use the function in model to process the data into database. Besides, it also route or redirect when the procedure is return success or failure.

view is the place that get the instant variable that initialize in controller ,and use it to render the data in proper format.

So,here the question for me in PHP.
I would like to create CRUD in php.I walked through many of the article or posts(in stackoverflow& others),but i got confused that some of the people saying different kind of things.

In my mind, model is the place that only related to data insertion/query to database. So,every query for my create,show,update,delete, i will put in my model.
here is my example for create_user function in my model.

function create_user($firstName, $lastName,$username, $password){
    $query = "INSERT INTO `users` (`user_id`, `first_name`, `last_name`, `email`, `username`, `password`, `created_at`, `handphone_no`, `street_address`, `city`, `state`, `country`, `postal`, `birthday`, `company_id`)
            VALUES (NULL, ?, ?, NULL, ?, ?, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2)";

    if($stmt = $this->conn->prepare($query)) {
        $stmt->bind_param('ssss', $firstName, $lastName,$username, $password);
        $stmt->execute();
    }

} 

So,my FIRST question: in my model, am i suppose to an object and pass to controller?? or just return true or false to indicate the success or failure of the process.

in my user controller,

class Users_controller {

private $user;

function __construct(){
    $this->user = New User();
}

function create($firstName, $lastName,$username, $password){
    $this->user->create_user($firstName, $lastName,$username, $password);
}
}

my SECOND question: for my CRUD, in rails, it will either find the id of the object and show/edit it or create/destroy a new model. So, my controller here have to return an object for me to render data in view? and how am i suppose to connect my form to the controller. From my form to pass the params to the controller.

so,right now Im thinking so far of that only, any guidance and clear example for me to understand more because Im new to php. Thanks you…

  • 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-06-09T23:35:59+00:00Added an answer on June 9, 2026 at 11:35 pm

    Okay, hopefully this answer won’t be too long, but here we go…

    Firstly, RoR is in fact a framework, so the closest thing you’ll get to that in PHP would be a framework. However, you will not find a rails clone (or anything close) in PHP. Also, nearly every PHP framework out there claims to implement MVC, but almost none of them do. Most of them present some sort of modified & simplified version of MVC with rampant SOLID violations and all sorts of other issues. Within this answer I’ll refer to these variations of MVC as “FMVC” for short. With all that being said, proper MVC is technically impossible in PHP due to the necessity of persistent models. (note: you can do this in PHP, but it’s not easy and will likely be some ugly/”hacky” code).

    Here’s my recommendation, if you’re up for some learning: If you have a project in mind, pick a framework that generally appeals to you, and go with it. Learn it inside and out, dive into the source code, get some of your code reviewed, and be sure to (mostly) ignore all of the nay-sayers of that particular framework. I say “mostly” because if you really want to learn MVC or OOP-PHP in general, the best way to do that is to look at existing implementations and truly understand the good, the bad, and the ugly parts of the code. What this will give you is a solid (excuse the pun) foundation of knowledge in SOLID principles, as well as SOLID violations.

    If you’re looking to write your own MVC framework or learn MVC in general, there’s a few things to understand first:

    1. In the OP it seems like you’re misunderstanding what exactly the model is; In the MVC pattern the “M” (model) is a layer. If you’d like a long-winded but extremely accurate description of a model, see this post by tereško, as it’s currently the best such answer on SO. In short the model layer is made up of many parts, namely Data Mappers, Domain Objects, and “Services.” Data mappers are similar to “model” classes in FMVC – they contain the database queries. Domain Objects is basically just a container for domain data. “Services” are the point of interaction with the model layer: you call the service to do something, and it does the work within the model layer. Generally you won’t be directly calling data mappers (or domain objects) outside of services.

    2. CRUD is not a thing, it’s a concept – a list of methods to include in the class (create, read, update, delete). Data Mappers generally contain CRUD methods (and by extension so do services, although sometimes a bit more abstract)

    3. To reiterate (because it’s very important), almost no PHP frameworks implement proper MVC, so looking to them for guidance on learning MVC is a bad idea. You might learn FMVC this way, but proper MVC is a long ways off from what they implement.

    4. If you don’t fully understand OOP and SOLID principles, coding in MVC will be a nightmare. Going back to and re-learning or refreshing on the basics of OOP is the first thing you should do if you want to learn MVC

    Now for your specific questions:

    1. This question doesn’t really make sense. Calls to the model layer are made through services, which generally pass a domain object to the relevant data mapper for processing. The data mapper returns the domain object (which contains all of the result data) back to the service, which was called from outside the model layer.

    2. This question also makes no sense – reading the post that I linked earlier should clear up some of the confusion.

    tl;dr – read this post.

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

Sidebar

Related Questions

First of all, I want to make something clear before I get yelled at:
Before I start, I want to make it clear that my code is working
Before you read on I just want to make something perfectly clear, Im not
Before down-voting or closing for duplicate questions, I want to make clear that I
I hope I can make myself clear in English and in what I want
I want make datetimepicker in my project. Using jquery how it is possible? I
To start things off, I want to make it clear that I'm not trying
For my NodeJS project, I want to make a simple module that will give
I want make a bash script which returns the position of an element from
I want make interactive application where user launches it and can do various task

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.