Skip to main content

Laravel 4 တြင္ Workbench သံုးျပဳျခင္း။

workbench အသံုးျပဳျခင္းအားျဖင့္ အက်ိဳးကေတာ့အမ်ားၾကီးပါပဲ။ project တခုကုိ လူဝုိင္းေရးတဲ့အခါ မင္းက ဘယ္အပုိင္းယူ ငါကဘယ္အပုိင္းယူဆိုပီးေတာ့ လုပ္ပါတယ္။ ဒါဆုိရင္ workbench တခုေဆာက္ေပးျပီးေတာ့ ေရးခိုင္းထားလုိ့ရပါတယ္ ။ အေပၚက main ကုိ ထိစရာမလိုေတာ့ပါဘူး။
အျခားေကာင္းတာေတြလဲအမ်ားၾကီးရွိပါေသးတယ္။

၁။ Workbench သြင္းျခင္း။
ပထမဆံုးသံုးျပဳႏိုင္ဖုိ့အတြက္  app/config/workbench.php ထဲမွာ name နဲ့  email ထည့္ေပးရမယ္။

ျပီးရင္ေတာ့ Terminal ထဲမွာ ေအာက္က ကြန္မန္းနဲ့ bench တခုျပဳလုပ္ပါတယ္။

php artisan workbench vendor/package --resources

vendor ကေတာ့ ကုိယ့္ကုမၸဏီ သို့မဟုတ္ ကုိယ့္နာမည္ထည့္လဲျဖစ္ပါတယ္၊package ကေတာ့ ကိုယ္ေရးမယ့္ package နာမည္ပါ။ ဥပမာ Dasbroad အတြက္ဆိုရင္  dashboardေပ့ါ။

ဒါဆိုရင္ root folder ထဲက workbench ထဲမွာ ကုိယ္ထည့္လိုက္တဲ့  vendor နာမည္နဲ့ ထဲမွာ ထည့္ထားတဲ့ package နာမည္တဲ့ ဖိုင္ေတြတခုေဆာက္လုပ္ျပီးျဖစ္ေနပါလိမ့္မယ္။( ဒီအဆင့္က အင္တာနက္လုိပါတယ္ )

ဒါျပီးရင္ေတာ့ verdor ထဲက package ထဲမွာ composer install ျပဳလုပ္ေပးရပါမယ္။မလုပ္ရင္ File not found ျပေနပါလိမ့္မယ္။

သူ ့ဖုိင္ structure ေတြကေတာ့ ပထမေတာ့ နဲနဲရူပ္ေပးမယ့္ ေနာက္ေတာ့လဲဆင္ေျပသြား ပါလိမ့္မယ္။

src ကေတာ့ တကယ့္ကုတ္ေတြသိမ္းရမယ့္ေနရာပါ။

သူ ့မွာ composer.json ဆိုပီး ဖိုင္သန့္သန့္တခုလဲထပ္ပါတယ္။အဲဒီေတာ့ ဒီ package အတြက္ packagist ကေန ကုိယ္သံုးမယ့္ဟာကုိ တန္းလာထည့္ထားျပီး သံုးလုိ့ရပါတယ္။

၂။ Provider ထည့္ျခင္း။
vendor/package/src/Vendor/Package/ ထဲမွာ PackageServiceProvider.php ဖုိင္တခုရွိပါတယ္။အဲဒီဖုိင္က အသက္ပါပဲ။




ဒါျပီးရင္ေတာ့ ကုိယ္ေဆာက္ထားတဲ့ package ကုိ main ကေန သံုးလုိ့ရေအာင္ app/config/app.php ထဲမွာ သြားေၾကာ္ျငာေပးရပါတယ္။

" Name space\Class Name"


၃။ Routes ဖုိင္ ထည့္ျခင္း။
ေနာက္ျပီးေတာ့ routes ဖိုင္ခ်ိတ္ရပါဦးမယ္ ။
Src ေအာက္က PackageServiceProvider.php ထဲမွာ  public function boot() ဆိုပီးပါပါတယ္။
အဲဒီ function ထဲမွာ ေအာက္က အတုိင္းထပ္ထည့္ရပါမယ္။

include __DIR__ . '/../../routes.php';

ျပီးရင္ေတာ့ src ထဲမွာ routes.php ဆိုပီးဖုိင္တခုထပ္ထည့္လုိက္ရင္ အဲဒီထဲဲမွာ route ကုိ တန္းေရးလုိ့ရပါျပီ။ အားသာခ်က္ကေတာ့ အေပၚက routes ကုိ ထိစရာမလိုေတာ့ဘူး ။

၄။ Filters ဖုိင္ထည့္ျခင္း။
filters အတြက္ဆုိရင္လဲ route လိုပဲ ေအာက္ကအတုိင္း သြားထည့္ေပးရင္ဆင္ေျပပါျပီ။

include __DIR__ . '/../../filters.php';



၅။ Controller ခ်ိတ္ျခင္း။
controllers ဖိုဒါအလုပ္လုပ္ဖို့အတြက္ကေတာ့ workbench ထဲက composer.json ထဲက autoload ထဲမွာ လမ္းေၾကာင္းသြားထည့္ေပးရပါတယ္။

    "autoload": {
        "classmap": [
            "src/migrations",
            "src/controllers"
        ],
        "psr-0": {
            "Yethusoe\\Dashboard\\": "src/"
        }
    },


ျပီးရင္ေတာ့ composer dump-auto လုပ္ေပးလုိက္ရင္ရပါျပီ။
controllers ဖုိဒါထဲမွာ  BaseController တခုတည္ေဆာက္ေပးရပါမယ္။

ပထမဆံုး workbench ထဲက src ထဲမွာ controllers ဖုိဒါထဲမွာ BaseController.php ဆုိပီးတခုေဆာက္လုိက္ပါ။ ျပီးရင္ေအာက္က အတုိင္းကူးထည့္လုိက္ပါ။

main controllers ထဲက BaseController.php နဲ့အတူတူပါပဲ။

<?php

class BaseController extends Controller {

/**
* Setup the layout used by the controller.
*
* @return void
*/
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}

}

ျပီးရင္ေတာ့ class BaseController extends Controller အေပၚမွာ Controller ကုိ use လုပ္ေပးရပါမယ္။
အဲဒါက main ထဲက app=> config => app.php ထဲက Alias မွာရွိပါတယ္

use Illuminate\Routing\Controller; ဆိုပီးထည့္ေပးလိုက္ရင္  controllers ဖိုဒါကုိလဲ အေပၚကနည္းအတုိင္း လိုအပ္သလုိသံုးျပဳလုိ့ရပါျပီ။


၆ ။ ဥပမာစမ္းျခင္း။
ေအာက္ကအတုိင္း workbench အလုပ္မလုပ္ စမ္းလုိ့ရပါတယ္ ။

routes.php ထဲမွာ ေအာက္ကအတုိင္းထည့္ပါ။

<?php
Route::get('/test', 'TestController@test');
 ?>

controllers ထဲမွာ TestController.php ဆုိပီးဖုိင္းတခုေဆာက္ပီးေအာက္က အတုိင္းထည့္ပါ။

<?php
class TestController extends BaseController
{
public function test(){
return "Return From Controller";
}
}
?>
ျပီးရင္ေတာ့ public ေနာက္မွာ test ထည့္ျပီးေခၚၾကည့္ရင္ရပါျပီ။
Controller မေတြ့ဘူးေျပာေနရင္ workbench ထဲမွာ composer dump-autoload ေနာက္တခါထပ္လုပ္ရင္ဆင္ေျပသြားပါလိမ့္မယ္။


အမွားပါရင္ comment ေပးပီးျပင္ေပးပါဗ်ာ။ေက်းဇူးတင္ပါတယ္။

Comments

Popular posts from this blog

Learning English Through Laughter : 3

Mr.Green went to Germany, because he had some work there.He came back last Monday, and his young wife met him at the airport. They walked to their car and passed a tall, pretty air-hostess. Mr. Green said to her , ' Goodbye, Miss Harris, ' and the air-hostess smiled and said, 'Good bye' too. Mrs. Green stopped and looked at the air-hostess .Then she said to her husband, 'How did you know her name?' 'That was easy,'answered Mr.Green. 'The names of the captain and all the screw were on a piece of paper in front of our seates.' 'What was the name of the captain?' Mrs. Green asked with a smile. Mr.Green launged and answered ,'I don't remember any of the other names.' 4/\/\@

Install Laravel installer in ubuntu

Terminal ဖြင့္ပီးေတာ့ ေအာက္က ကြန္မန္းထည့္ run ရပါတယ္။ composer global require "laravel/installer" ျပီးရင္ terminal ထဲမွာ laravel ဆိုပီး ရိုက္ၾကည့္ပါ။ေအာက္ကအတုိင္းေပၚရင္ေတာ့ အလုပ္လုပ္ပါျပီ။ တကယ္လုိ ့ laravel: command not found ဆိုပီးျပေနရင္ေတာ့ ေအာက္က Command ထပ္ရိုက္ထည့္ျပီး ျပန္စမ္းၾကည့္ပါ။ ဒါဆိုဆင္ေျပသြားမွာပါ။ export PATH="~/.composer/vendor/bin:$PATH"

Install node.js in ubuntu

ပ ထမဆံုး http://nodejs.org/ မွာ သြင္းမယ့္ ဖိုင္ကုိအရင္ေဒါင္းလိုက္ပါ။ ျပီးရင္  dependencie လိုအပ္တာေတြကုိ ေ အာက္က  ကြန္မန္းနဲ့ ႏွစ္ခုသြင္းပါ။ sudo apt-get install g++ curl libssl-dev apache2-utils sudo apt-get install git-core ျပီးရင္ေတာ့ ေအာက္က ကြန္မန္းနဲ့တဆင့္ျခင္းသြင္းရင္ ဆင္ေျပပါျပီ။ cd node { download ဆြဲထားတဲ့ဖိုင္ကုိ ျဖည္ျပီးေတာ့ အဲဒီဖိုင္ထဲဝင္ } ./configure make sudo make install ရမရစမ္းဖုိ့အတြက္က ေအာက္က tut ေလးစမ္းျပီးသိႏုိင္ပါတယ္။ ေအာက္က ကုတ္ေတြကုိ test.js ဆိုျပီးတခုခုေပးပီး တေနရာရာသိမ္းလုိက္ပါ။ var http = require ( 'http' ); http . createServer ( function ( req , res ) {   res . writeHead ( 200 , { 'Content-Type' : 'text/plain' });   res . end ( 'Hello Node.js\n' ); }). listen ( 8124 , "127.0.0.1" ); console . log ( 'Server running at http://127.0.0.1:8124/' ); သိမ္းျပီးရင္ Terminal ထဲကေန node test.js ဆိုျပီးေခၚရင္   Server running at http://127.0.0.1:8124/ ဆိုျပီးေပၚေ...