Commit 8299689d7c672b368a9d378863049d0b71a98d22
Update pengenalan-composer.md
k4ml committed on 2/6/2015, 9:10:40 AMParent: 68201f796962d301580da907fa279d45052455c1
Files changed
_tips/pengenalan-composer.md | changed |
_tips/pengenalan-composer.md | ||
---|---|---|
@@ -24,4 +24,30 @@ | ||
24 | 24 | php composer.phar install |
25 | 25 | Loading composer repositories with package information |
26 | 26 | Installing dependencies (including require-dev |
27 | 27 | ``` |
28 | +Setelah `composer` selesai download, anda boleh mula menggunakan library tersebut dalam *script* PHP anda dengan hanya menambah baris berikut:- | |
29 | + | |
30 | +```php | |
31 | + | |
32 | +require 'vendor/autoload.php'; | |
33 | +``` | |
34 | + | |
35 | +Contohnya, bina fail baru bernama `mail.php` seperti berikut:- | |
36 | + | |
37 | +```php | |
38 | + | |
39 | +require 'vendor/autoload.php'; | |
40 | + | |
41 | +$transport = Swift_SmtpTransport::newInstance('127.0.0.1', 25); | |
42 | +$mailer = Swift_Mailer::newInstance($transport); | |
43 | + | |
44 | +$message = Swift_Message::newInstance('Wonderful Subject') | |
45 | + ->setFrom(array('john@doe.com' => 'John Doe')) | |
46 | + ->setTo(array('kamal-test@mailinator.com')) | |
47 | + ->setBody('Here is the message itself') | |
48 | + ; | |
49 | + | |
50 | +$result = $mailer->send($message); | |
51 | +``` | |
52 | + | |
53 | +Dan anda boleh jalankannya melalui `php mail.php` dan email akan dihantar. |
Built with git-ssb-web