MVC Framework

  • Step

    Traditional approach

    Let us write a program using traditional approach

    
    
    class student
    {
        public $mark;
       
    
        function grade($ab,$bb,$cb,$db)
        {
            $marks=$ab+$bb+$cb+$db;
            if ($marks>=60)
            {
                $grade = "First Division";
            }
            else if($marks>=45)
            {
                $grade = "Second Division";
            }
            else if($marks>=33)
            {
                $grade = "Third Division";
            }
            else
            {
                $grade = "Fail";
            } 
            return $grade;                         
        }
    
        function report_card($aa,$ba,$ca,$da)
        {
            $grd= $this->grade($aa,$ba,$ca,$da);
            echo "<table border=1>
            <tr>
            <th colspan=2>report card</u></h2></th>
            </tr>
            <tr>
            <th>subject</th>
            <th>grade</th>
            </tr>
                <td>
                mathematics:
                </td>
                <td>".$aa."</td></tr>
                <tr> 
            <td>
                physics:
                </td>
                <td>".$ba."</td></tr>
                <tr>
            <td>
                chemistry:
                </td>
                <td>".$ca."</td></tr>
                <tr>
            <td>
                english:
                </td>
                <td>".$da."</td></tr>
                <tr>
                <td>
                total grade:
                </td>
                <td>".$grd."</td></tr>
                </table>";
        }
        
    }
    
    
    $objs=new student;
    $objs->report_card($objs->student1["mathematics"], $objs->student1["physics"], $objs->student1["chemistry"], $objs->student1["english"]);
    
    
    OR

    During, traditional approach of programming, the UI coding, business logic and applications data domain was written into a single file which creates lack of maintainability, testability as well as scalability of the application. SOLUTION:
    In MVC pattern, The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application, because it enables you to focus on one aspect of the implementation at a time.



    MVC approach



    MVC Example