How to make MVC framework

ဒီနေ့တော့ ရေးတာ ပြီးသွားပါပြီ။ အရင်တုန်းက ရေးထားတဲ့ library လေး ကောက်ထည့်ပြီးရင် ကျွန်တော် အရင်ကရေးထားတဲ့ framework က MVC ဖြစ်သွားပြီ။ MVC ရေးရတာ မခက်ပါဘူး။ OOP နားလည်ရင်ရပါပြီ။ ကျွန်တော် သုံးထားတဲ့ File Structure လေး ကြည့်ကြည့်ပါ။

index.php ကနေ init.php ကိုခေါ်တယ်။ အဲဒီကနေ router ကနေ တဆင့် Controller ကို ခေါ်တယ်။ router က ဝင်လာတဲ့ Address ကို controller နဲ့ action ခွဲပေးတယ်။

ဥပမာ။။ example.com/controller/action

ဆိုရင် controller နဲ့ action ကို router က ခွဲထုတ်ပေးတယ်။

Controller ကနေ Model ပြန်ခေါ်ဖို့ Loader သုံးတယ်။ Model ကနေ View ပြန်ခေါ်ဖို့ Loader ပဲပြန်သုံးတာပဲ။ ကဲ… ဒါပဲ။ ရိုးတယ်။ ရှင်းတယ်။ ဘာမှ ခက်ခက်ခဲခဲရေးစရာမလို။ ပြီးရင် လက်ရှိ ရေးထားတဲ့ Library တွေ ကောက်ထည့်လိုက်ရင် ပြီးပြီ။ MVC framework ရေးရတာ ထင်သလောက် မခက်ပါဘူးဗျာ။ ရေးထားတဲ့ source code တော့ လာမတောင်းနဲ့။ မပေးနိုင်ပါ။ opensource မဟုတ်သလို ပေးဖို့လည်း စိတ်ကူးမရှိဘူး။ ဒီလောက် ရေးရတာ လွယ်လွယ်လေးကို။ တကယ်လို့ မသိဘူးဆိုရင်တော့ အောက်က link ၂ ခုကနေ လေ့လာလို့ရပါတယ်။ controller code ကတော့ မနေ့က ရေးပေးဖူးတယ်။

http://www.phpro.org/tutorials/Model-View-Controller-MVC.html

http://net.tutsplus.com/tutorials/php/creating-a-php5-framework-part-1/

Write your own PHP MVC Framework (Part 1)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Saturngod

Subscribe now to keep reading and get access to the full archive.

Continue reading