0

How to make MVC framework

Posted February 24th, 2010 in Knowledgebase and tagged , , by saturngod

ဒီေန႕ေတာ့ ေရးတာ ျပီးသြားပါျပီ။ အရင္တုန္းက ေရးထားတဲ့ 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/

http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/


Leave a Reply