Joomla 1.5 Template တစ္ခု ပုံေဖာ္ၾကည့္ျခင္း

ကြၽန္ေတာ္ ဒီ Post မွာ Joomla 1.5 Template တစ္ခုကို ဘယ္လို create လုပ္မလဲ ဆိုတာကို ကြၽန္ေတာ္ သိထား သေလာက္ ေရးပါမယ္။ အရင္ဆုံးေတာ့ Joomla ကိုဘယ္လို Install လုပ္မယ္၊ Admin Panel ကေန Template ဘယ္လို ေျပာင္းမယ္ ဆိုတာေတြကိုေတာ့ သိထားဖို႔ လိုပါတယ္။ တကယ္လို႕ အဲဒါေတြကို သိခ်င္ရင္ေတာ့ ကြၽန္ေတာ့္ Joomla CMS Post အေဟာင္း ေတြထဲမွာ ရွိပါတယ္။ ကြၽန္ေတာ့္ Joomla 1.0 Post ေတြကို ဖတ္ျပီး စမ္းေနမွာ စိုးလို႕  ဖတ္တဲ့သူေတြ အဆင္ေျပ ေစဖို႔ Post Title ေတြမွာ Joomla 1.0 or Joomla 1.5 စသည္ျဖစ္ ထည့္ေပးထားပါတယ္။ ခုမွ Joomla ကိုစလုပ္မယ့္ သူေတြကို အၾကံျပဳခ်င္တာက ခုခ်ိန္မွာ Joomla က 1.6 ကိုေတာင္ သြားေနျပီ ျဖစ္လို႕ အနည္းဆုံး Joomla 1.5 ကိုစကိုင္ သင့္ပါတယ္။ Okay ဗ်ာ စလိုက္ၾက ရေအာင္။ ဘာမွ မလုပ္ခင္ Joomla 1.5 ကို install လုပ္ထားတယ္လို႕ ယူစလိုက္မယ္ဗ်ာ။

Joomla Default Template ကိုေလ့လာ ၾကည့္ျခင္း

အရင္ဆုံး Joomla 1.5 default template ကိုဖြင့္ၾကည့္မယ္ ဆိုရင္ Default Template ၃ခု ကိုေတြ႕ ရမယ္။


ေျပာမယ္ ဆိုရင္ေတာ့ Joomla root folder ေအာက္မွာ Template အတြက္ templates ဆိုတဲ့ folder ရွိေနျပီး Front-End မွာ သုံးမယ့္ template ေတြအားလုံး အဲဒီ Folder ေအာက္မွာ ရွိပါတယ္။

Template မ်ားကို Back-End မွ manage လုပ္ျခင္း

ခုန ကြၽန္ေတာ္ေျပာတဲ့ templates ေတြထဲက ဘယ္ template ကိုသုံးမယ္ ဆိုတာကို ေရြးခ်ယ္ေပးခ်င္ တယ္ဆိုရင္ေတာ့ Extension >> Template Manager ကေန လုပ္ေဆာင္ေပးႏိုင္ပါတယ္။

Template တစ္ခု တည္ေဆာက္ျခင္း

Article Manager ထဲကေန Article တစ္ခုကို စမ္းဖို႔ create လုပ္ျပီး Front End ကေနၾကည့္မယ္ဆိုရင္ ဒီလိုျမင္ ရပါမယ္။ ဒါကေတာ့ rhuk_milkyway ဆိုတဲ့ default template ကိုသုံးထာတာ ျဖစ္ပါတယ္။


အဲလိုမ်ိဳး template တစ္ခုကို လုပ္ခ်င္တယ္ ဆိုရင္ေတာ့ templates folder ထဲကိုသြားျပီး mytemplate_tut ဆိုျပီး folder အသစ္ တစ္ခု အရင္ေဆာက္ လိုက္ပါမယ္။ေနာက္တစ္ဆင္ အေနနဲ႔ ကေတာ့ mytemplate_tut folder ထဲမွာ index.php နဲ႔ templateDetails.xml files ႏွစ္ခု create လုပ္လိုက္ပါ။ Joomla Template တစ္ခု လုပ္ဖို႔ တကယ္ အခရာက်တာက အဲဒီ ၂ files ပဲျဖစ္ပါတယ္။

templateDetails.xml ကေတာ့ ကိုယ့္ template မွာသုံးမယ့္ module position, images, files ေတြအျပင္ template မွာ author, copyright, version စတာေတြကိုပါ ထည့္ေပးႏိုင္ တယ္ ဗ်ာ။ ေျပာမယ္ဆိုရင္ေတာ့ ကိုယ့္ template ရဲ႕ Setting File ပဲေပါ့။ Template ကို install လုပ္ရင္ အဲဒီ XML File ကေနစျပီး run တာျဖစ္ပါတယ္။

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 1.5//DTD template 1.0//EN" "http://www.joomla.org/xml/dtd/1.5/template-install.dtd">
<install version="1.5" type="template">
    <name>mytemplate_tut</name>
    <creationDate>02/09/10</creationDate>
    <author>Zack</author>
    <authorEmail>joomzack@gmail.com</authorEmail>
    <authorUrl>http://www.zack-notes.net</authorUrl>
    <copyright></copyright>
    <license>GNU/GPL</license>
    <version>1.0.0</version>
    <description>TPL_RHUK_MILKYWAY</description>

    <positions>
        
        <position>breadcrumb</position>
        <position>left</position>
        <position>right</position>
        <position>top</position>
        <position>footer</position>

    </positions>

</install>


index.php ကေတာ့ ကိုယ္ template ထဲမွာပါမယ့္ Layout ေတြ၊ module position ေတြအျပင္ ဘယ္ modules အတြက္ ဘယ္ CSS ကိုေခၚမယ္ ဘယ္ image ကိုထည့္မယ္ စတာေတြ အတြက္ ထည့္ေပး ထားတာ ျဖစ္ပါတယ္။ index.php ကိုဖြင့္ျပီး code ေလးနဲနဲေရး လိုက္ပါမယ္။

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >  
<head>  
<jdoc:include type="head" />  
</head>  
 
<body>  
 
<jdoc:include type="component" />  
 
</body>  
</html>


အဲဒီ Code ကိုၾကည့္မယ္ ဆိုရင္ <jdoc:include type="head" /> ကေတာ့ Browser မွာ Title ေတြေပၚဖို႔ အတြက္ပါ။ ေနာက္တစ္ခု ကေတာ့ <jdoc:include type="component" /> ပါ။ အဲဒါကေတာ့ content ေတြကို ျပခ်င္လို႕ include လုပ္တာ ျဖစ္ပါတယ္။ ဒါဆိုရင္ ကြၽန္ေတာ္တို႔ Back-End ကေန ခုလုပ္ထားတဲ့ template ေလးကို ေျပာင္းျပီး ျပန္ run ၾကည့္ရေအာင္။

ဒီလိုမ်ိဳး ျမင္ရတယ္ ဆိုရင္ေတာ့ mytemplate_tut ကိုေျပာင္းသြားျပီး ျဖစ္ပါတယ္။


Template တြင္ module position မ်ားကို ေနရာခ်ျခင္း

module position ေတြကို ေနရာ မခ်ခင္ ကိုယ့္ template မွာ module position ေတြကို templateDetails.xml ထဲမွာ သတ္မွတ္ထားခဲ့တာ မွတ္မိမယ္ ထင္ပါတယ္။အဲဒီ module positions ေတြကို ထည့္ခ်င္ရင္ေတာ့ ဒီ standard ကို လိုက္နာဖို႔ လို႕ပါတယ္။

<jdoc:include type="modules" name="position_name" />

ဒီေတာ့ဗ်ာ left နဲ႔ footer module positions ႏွစ္ခုကို ထည့္ေပးၾကည့္ရေအာင္။ index.php မွာ code ကို နဲနဲ ျပင္လိုက္ပါမယ္။

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >  
<head>  
<jdoc:include type="head" />  
</head>  
 
<body>  
 
<jdoc:include type="component" />  
   <jdoc:include type="modules" name="left" />  
<jdoc:include type="modules" name="footer" />  
</body>  
</html>



ဒါဆို ခုနလုပ္ထားတဲ့ footer position ကို module တစ္ခုထားၾကည့္ဖို႔ Extensions >> Modules Manager ကေန footer module ကို module position မွာ footer ေပးျပီး enable လုပ္ေပး လိုက္ပါ။

Front-End ကေန footer module ကိုသြားျပန္ၾကည့္မယ္ ဆိုရင္ေတာ့


Module Position အတိုင္း Home menu က left မွာရွိေနေသာ္လည္း CSS ေတြမထည့္ ရေသးလို႕ အထဲဝင္ ေနတယ္လို႕ ထင္ႏိုင္ပါတယ္။

Template တြင္ CSS မ်ားေပါင္း ထည့္ၾကည့္ျခင္း

ဟုတ္ျပီဗ်ာ ဒီေတာ့ ထင္သာျမင္သာေအာင္ CSS ေတြလိုက္ထည့္ျပီး ျပင္ၾကည့္လိုက္ရေအာင္။

* { 
    padding: 0; 
    margin:0; 
    } 
ul { 
    list-style:none; 
    }
.float_right{
    float: right;
   
}
.float { 
    float: left; 
    } 
.clear { 
    clear: both; 
    } 
#container { 
    width:960px; 
    margin: auto; 
    } 
#header { 
    background-color:#659EC7; 
    height: 150px; 
    } 
#content { 
    width: 660px; 
    text-align: center; 
 
    } 
#sidebar_left { 
    text-align: center; 
    background-color:#95B9C7; 
    width: 150px; 
    } 
#sidebar_right { 
    background-color:#95B9C7; 
    width: 90px; 
    } 
#footer { 
    background-color:#98AFC7; 
    text-align:center; 
    }


ဒီ code ေလးကို mytemplate_tut folder ေအာက္မွာ CSS လို႕ folder ေလးထပ္ေဆာက္ျပီး template.css အေနနဲ႔ သိမ္းထားလိုက္ပါ။

ဒါဆိုရင္ေတာ့ ဒီ CSS ေတြကို index.php ထဲကေန ျပန္ေခၚသုံးၾကည့္ဖို႔ code ကိုနဲနဲ modify လုပ္လိုက္ပါမယ္။

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >  
<head>  
<jdoc:include type="head" />  
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/mytemplate_tut/css/template.css" type="text/css" />  
</head>  
 
<body>  
<div id="container">  
    <div id="header"> Header </div>  
    <div id="sidebar_left" class="float"><jdoc:include type="modules" name="left" /></div>  
    <div id="content" class="float">  
        <jdoc:include type="component" />  
    </div>  
    <div id="sidebar_right"class="float">Right sidebar</div>  
    <div id="footer" class="clear"><jdoc:include type="modules" name="footer" /></div>  
</div>  
</body>  
</html>



ဒီတစ္ခါ Front-End ကို refresh လုပ္လိုက္မယ္ ဆိုရင္ေတာ့ ဒီလိုေလးေျပာင္းလဲ သြားပါမယ္။


module position အသစ္မ်ားကို ထပ္ေပါင္းထည့္ျခင္း

module position အသစ္ေတြကို ေပါင္းထည့္ခ်င္ရင္ေရာ??  ရတာေပါ့ဗ်ာ :) ဆက္ၾကည့္လိုက္ရေအာင္
user1,user2,user3 ဆိုတဲ့ module position ေနာက္ထပ္ သုံးခုကို ထည့္ေပးမယ္ ဆိုရင္ေတာ့ index.php မွာ ဒီလိုေလး ေျပာင္းသြားပါမယ္။

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >  
<head>  
<jdoc:include type="head" />  
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/mytemplate_tut/css/template.css" type="text/css" />  
</head>  
 
<body>  
<div id="container">  
    <div id="header"> Header and stuff</div>  
    <div id="sidebar_left" class="float"><jdoc:include type="modules" name="left" /></div>  
    <div id="content" class="float">  
        <jdoc:include type="component" />  
    </div>  

    <div id="sidebar_right"class="float">Right sidebar</div>  
    <div class="clear"></div>
    <div id="user1" class="float"><jdoc:include type="modules" name="user1" /></div>
    <div id="user2" class="float"><jdoc:include type="modules" name="user2" /></div>
    <div id="user3" class="float"><jdoc:include type="modules" name="user3" /></div>
    
    <div id="footer" class="clear"><jdoc:include type="modules" name="footer" /></div>  
</div>  
</body>  
</html>



template.css မွာလည္း ဒီလိုေလး ျပင္လိုက္မယ္။

* {  
    padding: 0;  
    margin:0;  
    }  
ul {  
    list-style:none;  
    }
.float_right{
    float: right;
    
}
.float {  
    float: left;  
    }  
.clear {  
    clear: both;  
    }  
#container {  
    width:960px;  
    margin: auto;  
    }  
#header {  
    background-color:#659EC7;  
    height: 150px;  
    }  
#content {  
    width: 660px;  
    text-align: center;  
 
    }  
#sidebar_left {  
    text-align: center;  
    background-color:#95B9C7;  
    width: 150px;  
    }  
#sidebar_right {  
    background-color:#95B9C7;  
    width: 90px;  
    }  
#footer {  
    background-color:#98AFC7;  
    text-align:center;  
    }  
#user1{
    width: 320px;
    background-color: #78c7c7;  
}

#user2{
    width: 320px;
    background-color:#43BFC7;  
}

#user3{
    width: 320px;
    background-color:#77BFC7;  
}



templateDetails.xml ကိုလည္း module position အသစ္ user1, user2, user3 ကိုထပ္ျပီး ထည့္ေပးလိုက္မယ္။

   

<positions>
        
        <position>breadcrumb</position>
        <position>user1</position>
        <position>user2</position>
        <position>user3</position>
        <position>left</position>
        <position>right</position>
        <position>top</position>
        <position>footer</position>

    </positions>


အားလုံးျပီးရင္ေတာ့ Back-End ကေနျပီး user1, user2, user3 position ေတြအတြက္ module အသစ္သုံးခုကို ထည့္ျပီး Front End ကေနျပန္ၾကည့္ မယ္ဆိုရင္ေတာ့ ဒီလိုေျပာင္း သြားတာ ကို ေတြ႔ရမယ္။



ခုေလာက္ဆိုရင္ေတာ့ Joomla 1.5 based template တစ္ခုကို ဘယ္လိုတည္ေဆာက္မယ္ ဆိုတာ idea ရေလာက္ျပီး လို႕ထင္ပါတယ္။ ကြၽန္ေတာ္ idea အၾကမ္းေလးေပၚမွာကိုယ္ပိုင္ စိတ္ကူး ဥာဏ္ရွိ သေလာက္ ကြန္႕ျမဴး ႏိုင္ၾကပါေစဗ်ာ။

 

CKEditor in CodeIgniter

Sunday, 29 August 2010 22:32

ကြၽန္ေတာ္ ဒီ Post မွာ CKEditor ကို CodeIgniter မွာ ဘယ္လိုေပါင္း ထည့္မလဲ ဆိုတဲ့ Tutorial ကိုေရးမွာ ျဖစ္ပါတယ္။ ဒါေၾကာင့္ CI မွာ Helper ေတြ၊ Library ေတြကို ဘယ္လိုေပါင္းထည့္လို႕ ရတယ္ ဆိုတာကို ေရးထားတဲ့ ဒီ Post ကိုအရင္ ဖတ္ထားဖို႔ လိုပါတယ္။

CI ထဲကို ေပါင္းထည့္မယ့္ CKEditor အေၾကာင္းေလး ဗဟုသုတ အျဖစ္ နဲနဲၾကည္ လိုက္ရေအာင္။ CKEditor ဆိုတာကေတာ့ Web ေပၚမွာ user friendly ျဖစ္ေအာင္ လုပ္ေပးထားတဲ့ WYSIWYG editor အမ်ိဳးအစားပဲ ျဖစ္ပါတယ္။ WYSIWYG ကဆိုတာကေတာ့ What-You-See-Is-What-You-Get ကိုေျပာတာ ျဖစ္ပါတယ္။ ကြၽန္ေတာ္တို႔ Word ထဲမွာ Font Size, Font color, Font Style ေတြ၊ Number & Bullet ေတြ၊ Table Format ေတြကို အလြယ္တကူ လုပ္ႏိုင္ သလိုမ်ိဳး Web Page ေတြမွာ CKEditor ကိုသုံးျပီး လုပ္ႏိုင္ပါတယ္။ Web based ျဖစ္တာေၾကာင့္ Word ကိုေတာ့ Feature ေတြအကုန္ ယွဥ္လို႕ မရေပမယ့္ အသုံးဝင္တဲ့ Editor တစ္ခု ျဖစ္တာကေတာ့ အေသအခ်ာပါပဲ ခင္ဗ်ာ။ CKEditor ဆိုတာကေတာ့ 2003 ေလာက္ထဲက စတင္ခဲ့တဲ့ FCKEditor ရဲ႕ new generation အျဖစ္ 2009 မွာေျပာင္းလဲ ခဲ့တာျဖစ္ပါတယ္။

ဒါေၾကာင့္ ခုခ်ိန္မွာ Google မွာ FCKEditor လို႔ရွာရင္လဲ CKEditor ကိုပဲ ေတြ႔ရပါ လိမ့္မယ္။

အဲဒီ အသုံးဝင္တဲ့ကို CI ထဲကို ဘယ္လို ေပါင္းထည့္ မလဲ ဆိုတာ ဆက္ၾကည့္ ရေအာင္။

1) Download CKEditor

ဒီမွာ CKEditor ကို အရင္ Download လုပ္ဖို႔ လိုပါတယ္။

2) Create folder in CI for CKEditor

Download လုပ္ထားတဲ့ Folder ကိုဖြင့္ လိုက္လို႕  _samples ၊  _sources folder ေတြကိုေတြ႔ ခဲ့ရင္ေတာ့  အဲဒီ Folder ေတြ မရွိလည္း အလုပ္လုပ္တာမို႔ Delete လုပ္ျပစ္ရင္ ပိုေကာင္းပါတယ္။ မလုပ္လဲ ျပသနာ မရွိေသာ္လည္း server ေပၚအတင္အခ်ေတြမွာ အခ်ိန္ၾကာတာေတြ ျဖစ္ေစႏိုင္ပါတယ္။ ျပီးရင္ေတာ့ js folder ကို system folder နဲ႔ level တူေဆာက္ေပးျပီး အဲဒီေအာက္မွာ ckeditor ဆိုျပီး ေနာက္ folder တစ္ခုထပ္ေဆာက္ျပီး ခုနက _samples ၊  _sources folder ေတြ Delete လုပ္ျပီး က်န္ေနတဲ့ files ေတြ၊ folders ေတြ အားလုံးကို အဲဒီ ေအာက္မွာ copy ကူးျပီး ထည့္လိုက္ပါ။ Folder Structure ကိုၾကည့္မယ္ ဆိုရင္ေတာ့



3) Add CKEditor Helper in CI

ဒီအဆင့္မွာ helper file ေရးရမွာ ျဖစ္လို႕ application/helpers ေအာက္မွာ file အသစ္ တစ္ခု ေရးျပီးထည့္ ေပးရပါမယ္။ ဒီမွာ ေရးျပေနရင္ အရွည္ၾကီး ျဖစ္သြားမွာ စိုးတာေၾကာင့္ ဒီေနရာမွာ Download လုပ္ျပီး application/helpers ကိုထည့္ေပး လိုက္ပါ။ File name ကိုေတာ့ ckeditor_helper.php လို႔ေပး လိုက္ပါ။ အဲဒီ file ကို ဖြင့္ၾကည့္မယ္ ဆိုရင္ CKEditor ကိုသုံးရန္ လိုအပ္တဲ့ Function ေတြကို စုေရးထားတာ ေတြ႔ရပါမယ္။ Author ေရးထားတဲ့ အတိုင္းသုံးရတာ အဆင္ေျပေနတဲ့ အတြက္ျပင္ေနဖို႔ မလိုပါ။

4) Create Controller

ကြၽန္ေတာ္ထည့္လိုက္တဲ့ helper ကိုျပန္ေခၚဖို႔ Controller ကိုဆက္ လုပ္ပါမယ္။ ckeditor.php လို႔ နာမည္ေပးျပီး ဒီ code ေလးကိုထည့္ ေပးလိုက္ပါ။

<?php

class Ckeditor extends Controller {
   
    public $data     =     array();
   
    public function __construct() {
       
        parent::Controller();

        $this->load->helper('url'); //You should autoload this one ;)
        $this->load->helper('ckeditor');
       
        //Ckeditor's configuration
        $this->data['ckeditor'] = array(
       
            //ID of the textarea that will be replaced
            'id'     =>     'content',
            'path'    =>    'js/ckeditor',
       
            //Optionnal values
            'config' => array(
                'toolbar'     =>     "Full",     //Using the Full toolbar
                'width'     =>     "550px",    //Setting a custom width
                'height'     =>     '100px',    //Setting a custom height
                   
            ),
       
            //Replacing styles from the "Styles tool"
            'styles' => array(
           
                //Creating a new style named "style 1"
                'style 1' => array (
                    'name'         =>     'Blue Title',
                    'element'     =>     'h2',
                    'styles' => array(
                        'color'             =>     'Blue',
                        'font-weight'         =>     'bold'
                    )
                ),
               
                //Creating a new style named "style 2"
                'style 2' => array (
                    'name'         =>     'Red Title',
                    'element'     =>     'h2',
                    'styles' => array(
                        'color'             =>     'Red',
                        'font-weight'         =>     'bold',
                        'text-decoration'    =>     'underline'
                    )
                )               
            )
        );
       

    }
   
    public function index() {
       
        $this->load->view('ckeditor', $this->data);
       
    }
}



$this->load->helper('ckeditor'); ကေတာ့ ခုနလုပ္ထားတဲ့ helper file ကိုျပန္ေခၚတာ ပါတယ္။
CKEditor အတြက္လိုအပ္တဲ့ configuration, styles စတာေတြကို လိုခ်င္တဲ့ အတိုင္းေရးျပီး $this->data['ckeditor'] ဆိုျပီး array ထဲကို ထည့္လိုက္ပါတယ္။

id - CKEditor ရဲ႕ ID ပါ။
path - CKEditor Source ေတြကို Download ခ်ျပီး js folder ေအာက္ထားခဲ့တာ မွတ္မိမယ္ ထင္ပါတယ္။ အဲဒီ path ကိုေျပာတာပါ။
config - ဒီမွာေတာ့ toolbar, width, height စတာေတြကို လိုအပ္သလို parameter ေပးႏိုင္ပါတယ္။
style - CKEditor မွာ style ဆိုတဲ့ dropdown ေလးရွိေနျပီး ကိုယ့္ေရးထားျပီးသားကို select လုပ္ျပီး style dropdown ထဲကေန style တစ္ခုခုကိုေရြးတာနဲ႔ auto ေျပာင္းသြားပါမယ္။ အဲဒီ dropdown ထဲမွာေပၚမယ္ style ေတြအတြက္ ေရးထားျခင္း ျဖစ္ပါတယ္။

အားလုံးျပီးသြားေတာ့ view ကိုေခၚရင္း အဲဒီ data array ကိုထည့္ေပး လိုက္ပါတယ္။
$this->load->view('ckeditor', $this->data);

5) Create View

ေနာက္ဆုံး အဆင့္အေနနဲ႔ ckeditor.php ဆိုတဲ့ view ကိုေဆာက္ျပီး ဒီ code ေလးထည့္ေပး လိုက္ပါ။ သုံးသြားတဲ့ display_ckeditor function ကေန ckeditor_helper.php ထဲမွာ ေရးထားျပီးသားကို ေခၚလိုက္တာ ျဖစ္ပါတယ္။

ဒါကေတာ့ Googling လုပ္ရင္း ရွာေတြ႔တာ ေလးကို ျပန္ေရး ထားတာ ျဖစ္လို႕ တျခားနည္း တစ္ခုခုနဲ႔ CI ထဲေပါင္းထည့္တာ ရွိရင္လည္း comment မွာေရးထား ခဲ့ႏိုင္ပါတယ္။

 

Ref: http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/


 

Extend in CodeIgniter Framework

Saturday, 28 August 2010 22:23

ဒီ Post မွာ အဓိကထားျပီး ေရးမွာ ကေတာ့ CodeIgniter Framework ေပၚမွာ ရွိေနျပီးသား Library, Helper ေတြနဲ႔ မလုံေလာက္ ရင္ ျဖစ္ေစ၊ ကိုယ့္ Project Requirement အရ ေရးထည့္ဖို႔ လိုလာရင္ ျဖစ္ေစ Library, Helper အသစ္ေတြကို ဘယ္လိုထည့္ မလဲ ဆိုတာကို ျဖစ္ပါတယ္။ တစ္ နည္း အားျဖင့္ CI Framework ကိုဘယ္လို Extend လုပ္မလဲ ဆိုတာလဲ ျဖစ္ပါတယ္။ ကြၽန္ေတာ္ ေရးထားျပီးသား CI Post ေတြကို ျပန္ဖတ္ခ်င္ရင္ေတာ့

  1. CodeIgniter and MVC for Beginners
  2. Structure and Configuration of CodeIgniter
  3. CodeIgniter Database Library
  4. CodeIgniter Form Helper
  5. Simple Data Entry in CodeIgniter
  6. Pagination with CodeIgniter
  7. File upload in CodeIgniter


How to add own Helper

Okay အရင္ဆုံး helper တစ္ခုဘယ္လို ေပါင္းထည့္ မလဲ ဆိုတာေလး ၾကည့္ရေအာင္။ CI Structure မွာ application နဲ႔ system ရွိေနျပီး Built-In Library ေတြ၊ Helper ေတြအားလုံးက system ေအာက္မွာပဲ ရွိတယ္ဗ်ာ။ ကိုယ့္ အသစ္ထည့္ ခ်င္တာကို အဲဒီ Folder ေတြေအာက္မွာ သြားမထည့္ ရပါဘူး။ ဒါဆိုဘယ္မွာ ထည့္ရမလဲ ဆိုေတာ့ ... application folder ေအာက္မွာလည္း helpers, libraries folder ေတြရွိေနပါတယ္။ အဲဒီမွာ ထည့္ေပးရပါမယ္။

 

ကြၽန္ေတာ္ကေတာ့ helpers folder ေအာက္မွာ calculation_helper.php  ဆိုျပီး php file အသစ္တစ္ခု ေဆာက္လိုက္တယ္။ အဲဒီမွာ  မွတ္သား စရာ တစ္ခုကေတာ့ file name မွာ ေနာက္က _helper ဆိုတာပါရပါမယ္။ ဆိုလိုတာကဗ်ာ abc_hepler.php, xyz_helper.php စသည္ျဖင့္ ေရွ႕က ျဖစ္ခ်င္တာ ျဖစ္ျပီး ေနာက္က _helper.php နဲ႔ ဆုံးေပးရမယ္။ ျပီးေတာ့ ေရးေနၾကအတိုင္းပဲ function ေရးလို႕ ရပါတယ္။ ကြၽန္ေတာ္ကေတာ့ function add_value ကိုေရးထားလိုက္ပါတယ္။ 

<?php

function add_value($val1,$val2){
    return $val1 + $val2;
}

 

အဲဒီ Code ကို Controller ထဲက ေခၚ ၾကည့္ဖို႔ controller တစ္ခုကို ဆက္ျပီးေဆာက္မယ္။ 

<?php


class Test extends Controller{


    function calculate(){
        
      

     $this->load->helper('calculation');
        
      

     $val1 = 5; 
      

     $val2 = 3;
      

     echo "Result is " . add_value($val1,$val2);
  

    }
}

test.php ဆိုျပီး နာမည္ေပး လိုက္မယ္ဗ်ာ။ ဒါက ခုန ကြၽန္ေတာ္ေရးထားတဲ့ Helper calculation ကို loading လုပ္တာပါ။

$this->load->helper('calculation');


ကြၽန္ေတာ္ လုပ္ထားတာ calculation_helper ျဖစ္ေပမယ့္ ျပန္ေခၚေတာ့ _helper မပါေတာ့ပါဘူး။ တကယ္လို႕ ကိုယ့္က abc_helper.php ကိုလုပ္ထားခဲ့ မယ္ဆိုရင္ေတာ့ $this->load->helper('abc'); ေပါ့ဗ်ာ။ Browser ကေန ဒီလို Run လိုက္မယ္ ဆိုရင္ေတာ့

http://localhost:8888/ci_extend/index.php/test/calculate/

ႏွစ္ခု ေပါင္းထားတဲ့ result ကိုျမင္ရဖို႔ သုံးသြားတဲ့ add_value ဆိုတာကေတာ့ calculation_helper.php ထဲက ေခၚသြားတာ ျဖစ္ပါတယ္။
ဒါဆိုရင္ေတာ့ CI မွာ Helper အသစ္တစ္ခု ဘယ္လိုထည့္ မယ္ဆိုတာ Idea အၾကမ္းေတာ့ ရမယ္ ထင္ပါတယ္။
:)

 

How to add own Library

Library အသစ္တစ္ခု ဘယ္လိုေပါင္းထည့္ မလဲ ဆိုတာကို ဆက္ျပီး ၾကည့္လိုက္ရေအာင္။ application ေအာက္က libraries folder မွာ ကိုယ္ထည့္ ခ်င္တဲ့ library အသစ္တစ္ခုကို ထည့္ေပးရမယ္။ ကြၽန္ေတာ္က hello ဆိုတဲ့ Library ကိုထည့္ ဖို႔ ဒီလိုေလး ေရးလိုက္တယ္ဗ်ာ။ file name ကေတာ့ hello.php ေပါ့ဗ်ာ။

<?php
class hello{

function message(){
    echo "How are you?";
}
    
}
?>



အဲဒီမွာ class hello ဆိုရင္ ရပါျပီ။ controllers ေတြ model ေတြေရးတုန္းကလို extends လုပ္စရာမလိုပါ။ ကြၽန္ေတာ္ေရးထားတဲ့ message ကို controller ကေန သုံးၾကည့္ဖို႔  ခုနကြၽန္ေတာ္ ေရးထားျပီးသား controller file ျဖစ္တဲ့ test.php မွာ ဒီ code ေလးကို ထပ္ေပါင္းလိုက္ရေအာင္။

function hello_lib(){
    $this->load->library('hello');
    $this->hello->message();
}



ျပီးရင္ေတာ့ Browser ကေန ဒီလိုေလး run ၾကည့္မယ္ ဆိုရင္ေတာ့ 
http://localhost:8888/ci_extend/index.php/test/hello_lib/
"How are you?" ဆိုတဲ့ message ကိုျမင္ရမွာ ျဖစ္ပါတယ္။

How to use resource from existing Libraries

အဲဒီ ကိုယ္ထည့္လိုက္တဲ့ Library မွာ ရွိေနျပီးသား library ေတြထဲက value ေတြ function ေတြကို ျပန္သုံးခ်င္ရင္ေရာ ဘယ္လို လုပ္မလဲ ဆိုတာေလးကို ၾကည့္ရေအာင္။ ခုန ေရးထားတဲ့ Library ထဲမွာ ဒီ code ေလးကိုထည့္ ၾကည့္မယ္ေနာ္။  
 

function message(){
        echo "How are you?";
        $this->load->library->('config');
}



အရင္ အရင္ ေတြတုန္းက controllers, models ေတြထဲကေန အဲလို သုံးရင္ error မတတ္ေပမယ့္ ခုခ်ိန္မွာေတာ့ ဒီလို error တတ္မယ္ဗ်ာ။

ဘာလိုလဲ ဆိုေတာ့ $this က point လုပ္ေနတာက hello class ကိုျဖစ္ေနလိုပဲ ျဖစ္ပါတယ္။ ဒီေတာ့ super class object ကိုျပန္ယူေပးဖို႔  လိုပါတယ္။ အဲဒါေၾကာင့္ Library ကို ဒီလိုေလး ျပင္လိုက္မယ္။

<?php
class hello{
    
    var $CI;
    
    function hello(){
        $this->CI = & get_instance();
        
    }
    
    function message(){
        echo "How are you?";
        $this->CI->load->library('config');
        echo "My Languages is " . $this->CI->config->item('language');
        //$this->load->library->('config');
    }
}
?>



Class ထဲမွာ သုံးဖို႔ CI ဆိုတဲ့ variable ထဲကို $this->CI = & get_instance(); ဆိုျပီး super object ကို Reference(&) ယူလိုက္ပါတယ္။ အဲဒါေၾကာင့္ ဒီေနရာေတြမွာ $this->CI->load->library('config'); လို႕ျပန္သုံးတဲ့ အခါ error မတတ္ေတာ့ပဲ သုံးလို႕ ရသြား တာ ျဖစ္ပါတယ္။ ေနာက္ Post  မွာ CKEditor Library ကိုဘယ္လို ေပါင္းထည့္  မလဲ ဆိုတာ ေရးပါမယ္။ ဖတ္ျပီး နားမလည္တာ မွားေနတာ မရွင္းတာေတြ ရွိေနရင္လည္း comment ေပးေဆြးေႏြး ေပးဖို႔ ေတာင္းဆိုပါတယ္။ :)

 

Ref: http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-extending-the-framework/

 

Page 1 of 59

«StartPrev12345678910NextEnd»

Login Form

Categories Table View

RSS Feed

JoomlaWatch Stats 1.2.9 by Matej Koval

Facebook Share

Share on facebook

mod_joomtouch

Version Iphone

Version Iphone by JoomTouch