Beruflich Dokumente
Kultur Dokumente
CreateasimpleToDoListinDooPHPPart1
Introduction
ThistutorialwillguideyouthroughallthestepsrequiredtogetstartedusingDooPHPthroughthecreationofasimple ToDoListApplication.Thetutorialissplitintoanumberofsectionsandyouwillneedtoreadtheguidefromthe begininginordertounderstandwhatsgoingon. Part1GettingStarted Part2TheSignupForm Part3UserAuthenticationComingSoon Part4TheToDoListComingSoon Part5AddingAJAXFunctionalityComingSoon
OurObjectiveforthisTutorial
InthistutorialwewillbecreatingasimpleToDooListManagerWebApplicationandthroughthecourseofthe tutorialwewillbecoveringthefollowingtopics: ObtainingandDeployingtheBaseDooPHPApplication SettinguptheMySQLDatabase
CreatingtheModels CreatingtheToDoManagerApplication SignupForm UserAuthentication UserHomePage TaskActions EnhancingyouapplicationwithAJAX Youcanviewademoofthefinishedprojecthere.Somescreenshotsofthefinalapplicationarealsoincludedbelow: TODO:IMAGESTOGOINHEREWHENIFINISH! TODO:UPDATETHEDEMOLINKABOVE
ObtainingandDeployingtheBaseDooPHPApplication
BeforeyoucanbeginworkingontheToDooListManageryouwillneedaccesstoaWebServer.Thisguideassumes youalreadyhavewebhostingorbetteryetrunningadevelopmentserverlocallywhichsupportsPHP5andaMySQL. IfyoudonotyethaveyourownservertousethenIsuggesttakingalookatusingaWAMPserveronyourlocal system:http://www.wampserver.com/en/. YouwillalsobeneedingacopyofDooPHP.Youcandownloadthelatestreleasefromhere(forthisdemoIamusing Version1.2).IFyouwanttousetheverylatestsourceforDooPHPtakealookanddownloadthecodefromhere: DooPHPonGoogleCode Onceyouhavedownloadedoneofthecompressedpackagesopenitandcopythedooframeworkfolderintothe projectsrootfolderandthecontentsoftheappfolderintoyourpublic_htmlfolder.Thisshouldthengiveyouafolder structuresimilartothefollowing: X:\todomanager\ dooframework\ public_html\ global\ protected\ tools\ .htaccess.example index.php IntheaboveexampleapachehasbeenconfiguredtohavetheDOCUMENT_ROOTsetto x:\todomanager\public_html\withtheprojectrootthereforebeing:x:\todomanager\ AtthispointweneedtomakeafewchangestotheconfigurationofDooPHPinorderforittoworkunderthefile structurebeingusedforthisdemo.Thereforeyoufirstneedtoopenthefile public_html\protected\config\common.conf.phpandmakethefollowingchanges: 1. Changethedate_default_timezone_set()toyourownlocaltimezone 2. Changethe$config[SITE_PATH]and$config[BASE_PATH]to:
1 . $ c o n f i g [ ' S I T E _ P A T H ' ] = d i r n a m e ( d i r n a m e ( d i r n a m e ( _ _ F I L E _ _ ) ) ) . D I R E C T O R Y _ S E P A R A T O R 2 . $ c o n f i g [ ' B A S E _ P A T H ' ] = d i r n a m e ( $ c o n f i g [ ' S I T E _ P A T H ' ] ) . D I R E C T O R Y _ S E P A R A T O R . ' d o o f r a m e w o r k ' . D I R E C T O R Y _ S E P A R A T O R
SettinguptheMySQLDatabase
OurToDooListManagerwillallowuserstosignupandregisterforanaccount.Thiswillrequirethemtopicka usernameandpasswordwhichwewilllaterusetoauthenticatetheuser.Inadditionwewillaskthemfortheiractual namesowecandisplaythistothemwhentheyhaveloggedin. EachregistereduserwillbeallowedtohaveasingleToDoListandeachusersToDoListwillbeprivatefromallthe otherusers.Wewillthereforerequire: AUsertabletohold: id username password name AndanothertableToDoItemtohold: id user_id task completed TherewillbeasimpleonetomanyrelationshipbetweenUsersandToDoItemswitheachuserabletohavemanyTo DoItems. Ihavealsodecidedtokeepthisdemoassimpleaspossiblesoalthoughwecouldcollectotherinformationlikethedue dateforataskandprovidingmultipleToDoListsperuserwewillfornowleavesuchextrafeaturesalonealthoughI encourageyoutotryaddingthesefeaturesyourselfasalearningexercise. InthisexampleIamusingadatabasecalledToDoManagerandtheSQLtocreatethetablesaboveisshowbelow:
0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . C R E A T E T A B L E ` T o D o M a n a g e r ` . ` U s e r ` ( ` i d ` I N T N O T N U L L A U T O _ I N C R E M E N T P R I M A R Y K E Y , ` u s e r n a m e ` V A R C H A R ( 2 0 ) N O T N U L L , ` p a s s w o r d ` C H A R ( 3 2 ) N O T N U L L , ` n a m e ` V A R C H A R ( 4 0 ) N O T N U L L ) C R E A T E T A B L E ` T o D o M a n a g e r ` . ` T o D o I t e m ` ( ` i d ` I N T N O T N U L L A U T O _ I N C R E M E N T P R I M A R Y K E Y , ` u s e r _ i d ` I N T N O T N U L L ,
1 1 . ` t a s k ` V A R C H A R ( 2 5 5 ) N O T N U L L , 1 2 . ` c o m p l e t e d ` B I T ( 0 ) N O T N U L L 1 3 . )
CreatingtheModels
NowthatwehaveourdatabasecreatedweneedtoletDooPHPknowaboutitsexistance.Todothiswemustfirst opentheDBconfigurationfilefoundinpublic_html\protected\config\db.conf.php. Youwillneedtouncommentthelasttwolinesstarting$dbconfig.Youmustalsospecifyyourdatabasescredentials.
1 . $ d b c o n f i g [ ' d e v ' ] = a r r a y ( ' l o c a l h o s t ' , ' T o D o M a n a g e r ' , ' u s e r n a m e ' , ' p a s s w o r d ' , ' m y s q l ' , t r u e ) 2 . $ d b c o n f i g [ ' p r o d ' ] = a r r a y ( ' l o c a l h o s t ' , ' T o D o M a n a g e r ' , ' u s e r n a m e ' , ' p a s s w o r d ' , ' m y s q l ' , t r u e )
Intheabovecodeyouwillneedtosetyourdatabasessettings.Theparametersare:HostName,DatabaseName, Username,Password,DatabaseEngineandlastelyifyouwanttouseapersistentconnection. DooPHPallowsustodefineboththedevelopmentandproductionsettingstobeusedforaccessingthedatabase.In Search... Random Share JoinChat thisexamplewewillassumethedetailsarethesamebutinrealworldapplicationsyouwilllikelyhavedifferent databasesettingsforthedevelopmentandproductionenvironments.DooPHPdeterminswhichsettingtousebasedon the$config["APP_MODE"]settingdefinedinthefilepublic_html\protected\config\common.conf.php.Thisis currentlysettodefaulttodev(developer)mode. WemustalsoinformDooPHPabouttherelationshipswhichexistinourdatabase.Weonlyhaveonerelationshipin thisdemowhichisamappingofoneUsertoManyToDoItem(ie.OneToMany).TotellDooPHPaboutthisyou needtoplacethefollowingcodejustabovethe$dbconfiglineswejustdefinedabove.
1 . $ d b m a p [ ' U s e r ' ] [ ' h a s _ m a n y ' ] [ ' T o D o I t e m ' ] = a r r a y ( ' f o r e i g n _ k e y ' = > ' u s e r _ i d ' ) 2 . $ d b m a p [ ' T o D o I t e m ' ] [ ' b e l o n g s _ t o ' ] [ ' U s e r ' ] = a r r a y ( ' f o r e i g n _ k e y ' = > ' i d ' )
CreatingtheToDoManagerApplication
NowthatwehavegottheBaseDooPHPapplicationsetupandwehavealsosetupandconfiguredourModelswecan startthinkingabouthowuserswillinteractwithourWebApplication. Wewillneedtoprovideuserswithanumberofpossibleactionstoperformandthesewillbesplitbetweenanumber ofControllerswhichwillgroupsimilaractionstogether.Userswillbeabletocarryoutthefollowingactionsonthe site: Signupforanaccount Login Logout ViewtheirownToDoList Addnewtaskstotheirlist Updatethestatusofaspecifiedtask(Incomple,Completed) Deleteatask Wewillthereforebreakthisdowninto2controllers.Onetohandeluserregistrationandauthenticationactivitiesand anothertomanagetheusersToDoList JustbeforewestartworkingontheseControllerswemustdeletesomefilesprovidedintheBaseApplicationwhich wenolongerneed.Thereforedeletethefollowingfiles public_html\toolsDeletethisfolder public_html\global\css\demo.cssDeletethisfile public_html\protected\config\formsDeletethisfolder public_html\protected\controller\*Deleteallfilesinthisfolder public_html\protected\viewc\*Deleteallfilesinthisfolder Youcanalsoopenupthepublic_html\protected\config\routes.conf.phpfileanddeleteallthelinesofcodebelowthe $admin=array(admin=>1234)(andthislineaswell)butkeeptheclosing?>phptag. Wearenowreadytostartcreatingoursignupform Part2CreatingtheSignupForm
16Comments
PreviousPost NextPost
Richard 21Sep,2009 +1
Richard
21Sep,2009
ai 22Sep,2009
Richard 22Sep,2009
img 12Dec,2009
!Greatworks! thanksalot!
soso_86_2@yahoo.com 4Jan,2010
whenyouwillposttheothers?
Richard 7Jan,2010
ImafraidthatrightnowIcannotgiveananswerbutitwillhopefullyhappensoon.
aboshooq 16Feb,2010
DearRichard, Icouldntgetitwork,,relatedtoroutingissue!! itsaysomethinglikethis: ERROR404notfound ThisishandlerbyaninternalRouteasdefinedincommon.conf.php$config['ERROR_404_ROUTE'] Yourerrordocumentneedstobemorethan512bytesinlength.IfnotIEwilldisplayitsdefaulterrorpage. Givesomehelpfulcommentsotherthan404 AlsocheckoutthelinkspageforalistofURLsavailableinthis demo. hereistheurlaf_do/app/index.php/gen_model
aboshooq 16Feb,2010
FarhadSakhaei 18Apr,2010
Richard 21Apr,2010 +1
Thanks,Justcorrectedthem
wrlee 16Jul,2010
IamlookingforwardtotipsonAjaxusage.
Search...
OurSponsors ChooseLanguage
English Russian Deutsch Espaol Arabic Portugese
PopularTags
FindTutorial
Easy Normal Difficult
Categories
Demos&Snippets(4) News&Updates(2) Screencast(1) Tutorials(17)
RecentComments
kukatonIntrotoDooPHPslides(PHPMalaysiameetup2011) MilosKovackionUsingDooTranslatorfortranslation WebdevGreeceonUsingDooTranslatorfortranslation MilosKovackionHandlingsessionswithoutApachesessions TonCreateasimpleToDoListinDooPHPPart2
Blogroll
DevelopmentBlog Documentation Forum GoogleCode Home About Contact Forum AllcontentscopyrightLearnDooPHP.Allrightsreserved.ThemedesignbyWebKreation.