Nasıl sınıfları kullanmadan MVC fikirleri kullanabilirsiniz?

1 Cevap php

Şu an itibariyle, hala sınıflar üzerinde titrek duyuyorum, bu yüzden benim site için herhangi sınıfları kullanmak istemiyorum. Ben hala sınıfları ile çalışıyorum.

Ama nasıl sınıfsız MVC fikri uygulayabilirsiniz?

Bir MVC için bu iş olur?

index.php (görünüm)

index_controller.php

index_model.php

    Is this right for what a MVC should be? 
View: show html, css, forms 
Controller: get $_POST from forms and any data from the user, get info from db 
Model: do all the functions, insert/delete in db, etc

Temelde, görünüm için tüm denetleyicisi için toplama veri ve model için mantığı HTML / css ayrı. Ve sadece require_oncenin hepsini kullanarak bağlayın.

1 Cevap

Controller: Sizin index.php, kabul ve istekleri yönlendiren. Bu kesinlikle bir 'sınıfsız' komut olabilir. Bu kontrolör ve 'ön denetleyicisi' hem de hareket edecekti.

View(s): sunum komut koleksiyonu, senin kontrolörü tarafından dahil belirli komut. Esasen kontrolörünün değişken kapsamı veri 'alma'.

Model(s): veri erişimi sağlayan fonksiyonları bir koleksiyon. Denetleyici bir istek için dahil ne belirler.

Tabii, bu can yapılabilir, ancak çok sınıfları (OOP) kullanarak değil gevşek. Burada bir example denetleyici might neye hızlı. Inanılmaz bir şey, sadece bir fikir. Denetleyicisi gösteren model / görünüm biraz ışık tutacak hem de olmalıdır.

<?php
  $action = getAction(); //parse the request to find the action
  switch($action){
    case 'list':
      include('models/todolist.php'); //include the model
      $items = todolistGetItems(); //get the items using included function
      include('views/todolist/list.php'); //include the view
      break;
    case 'add':
      if(!empty($_POST['new'])){ 
        include('models/todolist.php'); //include the model
        todolistAddItem($_POST); //add the item
        $items = todolistGetItems(); //get the items using included function
        include('views/todolist/list.php'); //include the view
      } else {
        include('views/todolist/add.php'); //include the view
      }
  }