首先需要install Composer
https://getcomposer.org/
打開你的終端機
Finder->工具->前往資料夾
/應用程式/工具程式/終端機.app
https://getcomposer.org/
打開你的終端機
Finder->工具->前往資料夾
/應用程式/工具程式/終端機.app
php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php php -r "if (hash('SHA384', file_get_contents('composer-setup.php')) === '41e71d86b40f28e771d4bb662b997f79625196afcca95a5abf44391188c695c6c1456e16154c75a211d238cc3bc5cb47') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
composer global require "laravel/installer"
set PATH
vi ~/.bash_profile
以下為本機備份
# The next line updates PATH for the Google Cloud SDK.
source '/Users/attz/gcloud auth login/google-cloud-sdk/path.bash.inc'
# The next line enables bash completion for gcloud.
source '/Users/attz/gcloud auth login/google-cloud-sdk/completion.bash.inc'
export SCALA_HOME="/usr/local/share/scala"
export ACTIVATOR="/Applications/activator"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home"
export LARAVEL_HOME="~/.composer/vendor/bin"
export PATH="$SCALA_HOME/bin:$PATH"
export PATH="$ACTIVATOR:$PATH"
export PATH="$JAVA_HOME:$PATH"
export PATH="$LARAVEL_HOME:$PATH"
export PATH
你只要輸入以下即可
export LARAVEL_HOME="~/.composer/vendor/bin"
export PATH="$LARAVEL_HOME:$PATH"
export PATH
查看專案版本
php artisan --version
->Laravel Framework version 5.2.23
開始建立專案
laravel new blog
設定mamp路徑為
<你的路徑>/blog/
public/
cd
blog
編輯 vi Http/routes.php
Route::get('users', function()
{
return 'Users!';
});
編輯目錄下 blog/public/.htaccess
vi
public/
.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
完成
http://localhost/users
先下個小結… 比Yii 還需要多一點的設定摸索…
進階
編輯 vi Http/routes.php
Route::get('users', function() { return view('users'); });
編輯
vi resources/views/
layout.blade.php
<html>
<body>
<h1>ATTZ Quickstart</h1>
@yield('content')
</body>
</html>
編輯
vi resources/views/
users.blade.php
@extends('layout')
@section('content')
Users!
@stop
進階 指定 Controller
cp
app/Http/Controllers/
Controller.php
app/Http/Controllers/
PhotoController.php
vi
PhotoController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use App\Http\Controllers\Controller;
class PhotoController extends BaseController
{
public function index()
{
return view('photo');
}
}
編輯 增加 vi app/Http/routes.php
Route::resource('photo', 'PhotoController');
編輯
vi resources/views/photo.blade.php
@extends('layout') @section('content') MyPhoto @stop
完成
http://localhost/photo
進階 指定
vi
app/Http/Controllers/
PhotoController.php
<?php namespace App\Http\Controllers; use Illuminate\Routing\Controller as BaseController; use App\Http\Controllers\Controller; class PhotoController extends BaseController { public function index() { return view('photo'); }
public function index2()
{
return view('photo2');
}
}
編輯 增加 vi app/Http/routes.php
Route::
resource
('photo2', '
PhotoController
@index2');
編輯
vi resources/views/photo2.blade.php
@extends('layout') @section('content') MyPhoto2 @stop
完成
http://localhost/photo2
留言