วันเสาร์ที่ 9 กรกฎาคม พ.ศ. 2559

How to Download Composer for using Slim (a micro framework for PHP)



Step 1 : Download and run Composer-Setup.exe

Step 2 : Open Command Prompt on Windows and Run Script


-Download the installer to the current directory
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

-Verify the installer SHA-384 which you can also cross-check here
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

-Run the installer
php composer-setup.php

-Remove the installer
php -r "unlink('composer-setup.php');"

-----------------------After Install and Telling Message-------------------------
All settings correct for using Composer
Downloading 1.1.3...
Composer successfully installed to: C:\Users\suttipong\composer.phar
Use it: php composer.phar

-Update Composer
php composer.phar self-update

HOW TO USE COMPOSER


Example : Create Project laravel with Composer : 
composer create-project laravel/laravel exampleProject --prefer-dist




Problems 1 : How to import vendor folder

If you have the problem (vendor/autoload.php) in your php file it's has not work.



Autoload File has not work and it show message in the windows


How to....

Step 1 : copy composer.phar file into your folder in server and you write the command


Step 2 : From this command. It has the generate file (vendor folder, composer.lock) in your folder


Problems 2 : class slim/slim not found with composer

You will must have to write script for test.

-How to test Autoload of Slim

<?php
   require 'vendor/autoload.php';   //call Autoload PHP Page
   $app = new \Slim\Slim();          //call Slim PHP class
   $app->get('/', function () {         //get root path
   echo "Hello World!";
});
$app->run();

-How to test Slim class

<?php
    //require 'Slim/Slim.php';
    require 'vendor/slim/slim/Slim/Slim.php';
    $app = new Slim();
    $app->get('/hello', 'hello');        //call hello page and call method hello
    $app->get('/hello/:name', function ($name) {
    echo "Hello, $name";
});
$app->run();

function hello() {
    echo "Hello World.";
}
?>

Reference :

Problems 3 : xampp server 404 page not found

index.php
<?php 
// Pull in our bootstrap file.
require_once '../src/ProjectName/bootstrap.php';
$app->run();
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteRule ^ index.php [QSA,L]
<?php 
require_once '../vendor/autoload.php';
$app = new \Slim\App();
require_once 'Routes.php';
example.php
$app->get('/example/{name}', function ($request, $response, $args) {
    echo 'Hello ' . $args['name'];
}

Problems 4 : How to require function between class with using root path in PHP folder

/A
   foo.php
   tar.php
   B/
       bar.php
If you call foo.php (ex: http://example.com/foo.php), the working directory will be /A/. If you call bar.php (ex: http://example.com/B/bar.php), the working directory will be /A/B/.
foo.php call bar.php
<?php
require_once( 'B/bar.php' );
?>
bar.php call tar.php
<?php
require_once( 'tar.php');
?>
--------------------------------------------------------------------
URL :

1.) Composer - Dependency Management for PHP
https://github.com/kullawattana/composer

2.) Slim Framework 3 Skeleton Application
https://github.com/slimphp/Slim-Skeleton

3.) Download Composer for Create laravel and Slim Project
https://getcomposer.org/download/

4.) Laravel Project
https://laravel.com/docs/4.2/quick

5.) Install Composer on Windows
https://www.youtube.com/watch?v=ZocYVPP3nQY

6.) CURL
http://php.net/manual/en/book.curl.php
top.sk Web Developer

I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.