Reference
- https://github.com/felixfbecker/vscode-php-intellisense
php coding
Reference
You need to get “composer” first
#-> composer create-project –prefer-dist laravel/laravel:^7.0 blog
Laravel has “artisan” file at Root directory.
#-> php artisan key:generate “PHP artisani kosturur, -arguments i pass edersin. ”
web :80/laravel/blog/public/
# -> Routes Located : project/routes/web.php
1 2 3 |
Route::get('/', function () { return view('welcome'); }); |
#-> views Located : project/resources/views/welcome.blade.php
# -> Middleware : Between Request – And Response Filter (Config Stored at project/Http/Kernel.php)
1 |
php artisan make:middleware AgeMiddleware |
1 2 3 4 5 6 7 8 |
namespace App\Http\Middleware; use Closure; class AgeMiddleware { public function handle($request, Closure $next) { return $next($request); } } |
1 2 3 4 5 6 7 8 9 |
namespace App\Http\Middleware; use Closure; class RoleMiddleware { public function handle($request, Closure $next, $role) { echo "Role: ".$role; !!!<<<<<<<<<<<<<< return $next($request); } } |
1 2 3 4 |
Route::get('role',[ 'middleware' => 'Role:editor', <<< !! Role : -> editor 'uses' => 'TestController@index', <<<< !!!!!!! Classs -> function ]); |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class TestController extends Controller { public function index() { echo "<br>Test Controller."; } } |
Another Route
1 2 3 4 |
Route::get('terminate',[ 'middleware' => 'terminate', 'uses' => 'ABCController@index', ]); |
1 2 3 4 5 6 7 8 9 10 11 |
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class ABCController extends Controller { public function index() { echo "<br>ABC Controller."; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
namespace App\Http\Middleware; use Closure; class TerminateMiddleware { public function handle($request, Closure $next) { echo "Executing statements of handle method of TerminateMiddleware."; return $next($request); } public function terminate($request, $response) { echo "<br>Executing statements of terminate method of TerminateMiddleware."; } } |
#-> Changing Default NameSpace
1 |
php artisan app:name SocialNet |
#-> Controller
1 |
php artisan make:controller <controller-name> --plain |
1 |
Route::get(‘base URI’,’controller@method’); |
1 2 3 4 5 6 7 8 9 |
namespace App\Http\Middleware; use Closure; class SecondMiddleware { public function handle($request, Closure $next) { echo '<br>Second Middleware'; return $next($request); } } |
Consstruct
1 2 3 |
public function __construct() { $this->middleware('auth'); } |
Controller Calls Middleware
1 2 3 4 |
UserController extends Controller { public function __construct() { $this->middleware('Second'); // <<<<<<<<<<<< } |
#-> Path Route
1 |
Route::resource('my','MyController'); |
GET | /my | index | my.index |
GET | /my/create | create | my.create |
POST | /my | store | my.store |
GET | /my/{my} | show | my.show |
GET | /my/{my}/edit | edit | my.edit |
PUT/PATCH | /my/{my} | update | my.update |
DELETE | /my/{my} | destroy | my.destroy |
# You Can Assign Interface – Implicit Controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class ImplicitController extends Controller { private $myclass; public function __construct(\MyClass $myclass) { $this->myclass = $myclass; } public function index() { dd($this->myclass); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
class MyClass{ public $foo = 'bar'; } Route::get('/myclass','ImplicitController@index'); /// app/Http/Controllers/ImplicitController.php <?php // -------------------------------------------------- namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class ImplicitController extends Controller { public function index(\MyClass $myclass) { dd($myclass); } } |
#-> URL Checking
1 |
php artisan make:controller UriController –plain |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
class UriController extends Controller { public function index(Request $request) { // Usage of path method $path = $request->path(); echo 'Path Method: '.$path; echo '<br>'; // Usage of is method $pattern = $request->is('foo/*'); echo 'is Method: '.$pattern; echo '<br>'; // Usage of url method $url = $request->url(); echo 'URL method: '.$url; } |
1 |
Route::get('/foo/bar','UriController@index'); |
1 |
$name = $request->input('username'); |
#-> Post Registration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
// resources/views/register.php <form action = "/user/register" method = "post"> <input type = "hidden" name = "_token" value = "<?php echo csrf_token() ?>"> ------------------ php artisan make:controller UserRegistration --plain app/Http/Controllers/UserRegistration.php class UserRegistration extends Controller { public function postRegister(Request $request) { //Retrieve the name input field $name = $request->input('name'); echo 'Name: '.$name; echo '<br>'; //Retrieve the username input field $username = $request->username; echo 'Username: '.$username; echo '<br>'; //Retrieve the password input field $password = $request->password; echo 'Password: '.$password; } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- Route::get('/register',function() { return view('register'); }); Route::post('/user/register', array('uses'=>'UserRegistration@postRegister')); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- |
#-> Response with cookie
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
//Create a response instance $response = new Illuminate\Http\Response('Hello World'); //Call the withCookie() method with the response method $response->withCookie(cookie('name', 'value', $minutes)); //return the response return $response; // ----------------------------------------------------------- //’name’ is the name of the cookie to retrieve the value of $value = $request->cookie('name'); php artisan make:controller CookieController --plain class CookieController extends Controller { public function setCookie(Request $request) { $minutes = 1; $response = new Response('Hello World'); $response->withCookie(cookie('name', 'virat', $minutes)); return $response; } public function getCookie(Request $request) { $value = $request->cookie('name'); echo $value; } } Route::get('/cookie/set','CookieController@setCookie'); Route::get('/cookie/get','CookieController@getCookie'); |
#->
1 2 3 4 5 6 7 8 |
/// return response($content,$status) ->header('Content-Type', $type) ->header('X-Header-One', 'Header Value') ->header('X-Header-Two', 'Header Value'); Route::get('/header',function() { return response("Hello", 200)->header('Content-Type', 'text/html'); }); |
1 2 3 4 |
Route::get('/cookie',function() { return response("Hello", 200)->header('Content-Type', 'text/html') ->withcookie('name','Virat Gandhi'); }); |
1 2 3 4 5 |
app/Http/routes.php Route::get('json',function() { return response()->json(['name' => 'Virat Gandhi', 'state' => 'Gujarat']); }); |
1 2 3 |
Route::get('/test', function() { return view('test'); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
resources/views/test.php <html> <body> <h1><?php echo $name; ?></h1> </body> </html> app/Http/routes.php Route::get('/test', function() { return view('test',[‘name’=>’Virat Gandhi’]); }); |
#-> ServiceProvider : Sharing data with all views.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
Route::get('/test', function() { return view('test'); }); Route::get('/test2', function() { return view('test2'); }); // resources/views/test.php & resources/views/test2.php <html> <body> <h1><?php echo $name; ?></h1> </body> </html> // // app/Providers/AppServiceProvider.php <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { view()->share('name', 'Virat Gandhi'); } /** * Register any application services. * * @return void */ public function register() { // } } |
# -> Using Blade : new View
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
resources/views -> master.blade.php <html> <head> <title>DemoLaravel - @yield('title')</title> </head> <body> @yield('content') </body> </html> //---------- Blade @extends child.blade.php @extends('layouts.app') @section('title', 'Page Title') @section('sidebar') @parent <p>This refers to the master sidebar.</p> @endsection @section('content') <p>This is my body content.</p> @endsection |
#-> welcome . blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> @if (Route::has('login')) <div class="top-right links"> @auth <a href="{{ url('/home') }}">Home</a> @else <a href="{{ route('login') }}">Login</a> @if (Route::has('register')) <a href="{{ route('register') }}">Register</a> @endif @endauth </div> @endif |
#->
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
Route::get('user/profile', ['as' => 'profile', function () { // }]); //-------------------------------------------------------- resources/views/test.php. <html> <body> <h1>Example of Redirecting to Named Routes</h1> </body> </html> //-------------------------------------------------------- app/Http/routes.php Route::get('/test', ['as'=>'testing',function() { return view('test2'); }]); Route::get('redirect',function() { return redirect()->route('testing'); }); Step 3 − Visit the following URL to test the named route example. http://localhost:8000/redirect //-------------------------------------------------------- Redirecting to Controller Actions Not only named route but we can also redirect to controller actions. We need to simply pass the controller and name of the action to the action method as shown in the following example. If you want to pass a parameter, you can pass it as the second argument of the action method. return redirect()->action(‘NameOfController@methodName’,[parameters]); app/Http/Controllers/RedirectController.php. app/Http/Controllers/RedirectController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class RedirectController extends Controller { public function index() { echo "Redirecting to controller's action."; } } Step 4 − Add the following lines in app/Http/routes.php. app/Http/routes.php Route::get('rr','RedirectController@index'); Route::get('/redirectcontroller',function() { return redirect()->action('RedirectController@index'); }); |
#-> Error Logging
1 2 3 4 5 6 |
APP_DEBUG set in the environment file .env APP_DEBUG should be true but config/app.php file. 'log' => 'daily' |
#-> Forms
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
composer require illuminate/html Step 3 − Now, we need to add the package shown above to Laravel configuration file which is stored at config/app.php. Open this file and you will see a list of Laravel service providers as shown in the following image. Add HTML service provider as indicated in the outlined box in the following image. # https://www.tutorialspoint.com/laravel/laravel_forms.htm -> From .php view fiels, you can access Form Fields {{ Form::open(array('url' => 'foo/bar')) }} // echo Form::text('username'); echo Form::password('password'); {{ Form::close() }} # ------------------------------------------------------------ resources/views/form.php <html> <body> <?php echo Form::open(array('url' => 'foo/bar')); echo Form::text('username','Username'); echo '<br/>'; echo Form::text('email', 'example@gmail.com'); echo '<br/>'; echo Form::password('password'); echo '<br/>'; echo Form::checkbox('name', 'value'); echo '<br/>'; echo Form::radio('name', 'value'); echo '<br/>'; echo Form::file('image'); echo '<br/>'; echo Form::select('size', array('L' => 'Large', 'S' => 'Small')); echo '<br/>'; echo Form::submit('Click Me!'); echo Form::close(); ?> </body> </html> # ------------------------------------------------------- app/Http/routes.php Route::get('/form',function() { return view('form'); }); |
#-> Localization
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
resources/views resources/lang/en/lang.php <?php return [ 'msg' => 'Laravel Internationalization example.' ]; ?> resources/lang/fr/lang.php. <?php return [ 'msg' => 'Exemple Laravel internationalisation.' ]; ?> resources/lang/de/lang.php <?php return [ 'msg' => 'Laravel Internationalisierung Beispiel.' ]; ?> php artisan make:controller LocalizationController --plain /Http/Controllers/LocalizationController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class LocalizationController extends Controller { public function index(Request $request,$locale) { //set’s application’s locale app()->setLocale($locale); //Gets the translated message and displays it echo trans('lang.msg'); } } app/Http/routes.php Route::get('localization/{locale}','LocalizationController@index'); url:80/localization/de |
#-> Session
1 |
$value = $request->session()->get('key'); |
1 |
$request->session()->put('key', 'value'); |
1 |
$request->session()->forget('key'); |
1 |
$request->session()->forget('key'); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
php artisan make:controller SessionController --plain app/Http/Controllers/SessionController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class SessionController extends Controller { public function accessSessionData(Request $request) { if($request->session()->has('my_name')) echo $request->session()->get('my_name'); else echo 'No data in the session'; } public function storeSessionData(Request $request) { $request->session()->put('my_name','Virat Gandhi'); echo "Data has been added to session"; } public function deleteSessionData(Request $request) { $request->session()->forget('my_name'); echo "Data has been removed from session."; } } app/Http/routes.php Route::get('session/get','SessionController@accessSessionData'); Route::get('session/set','SessionController@storeSessionData'); Route::get('session/remove','SessionController@deleteSessionData'); host:8000/session/set |
#-> Validation Controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
/* The $errors variable will be an instance of Illuminate\Support\MessageBag. Error message can be displayed in view file by adding the code as shown below. */ @if (count($errors) > 0) <div class = "alert alert-danger"> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif php artisan make:controller ValidationController --plain app/Http/Controllers/ValidationController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class ValidationController extends Controller { public function showform() { return view('login'); } public function validateform(Request $request) { print_r($request->all()); $this->validate($request,[ 'username'=>'required|max:8', 'password'=>'required' ]); } } resources/views/login.blade.php <html> <head> <title>Login Form</title> </head> <body> @if (count($errors) > 0) <div class = "alert alert-danger"> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <?php echo Form::open(array('url'=>'/validation')); ?> <table border = '1'> <tr> <td align = 'center' colspan = '2'>Login</td> </tr> <tr> <td>Username</td> <td><?php echo Form::text('username'); ?></td> </tr> <tr> <td>Password</td> <td><?php echo Form::password('password'); ?></td> </tr> <tr> <td align = 'center' colspan = '2' ><?php echo Form::submit('Login'); ? ></td> </tr> </table> <?php echo Form::close(); ?> </body> </html> app/Http/routes.php Route::get('/validation','ValidationController@showform'); Route::post('/validation','ValidationController@validateform'); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
Form::file('file_name'); Form::open(array('url' => '/uploadfile','files'=>'true')); resources/views/uploadfile.php <html> <body> <?php echo Form::open(array('url' => '/uploadfile','files'=>'true')); echo 'Select the file to upload.'; echo Form::file('image'); echo Form::submit('Upload File'); echo Form::close(); ?> </body> </html> php artisan make:controller UploadFileController --plain app/Http/Controllers/UploadFileController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class UploadFileController extends Controller { public function index() { return view('uploadfile'); } public function showUploadFile(Request $request) { $file = $request->file('image'); //Display File Name echo 'File Name: '.$file->getClientOriginalName(); echo '<br>'; //Display File Extension echo 'File Extension: '.$file->getClientOriginalExtension(); echo '<br>'; //Display File Real Path echo 'File Real Path: '.$file->getRealPath(); echo '<br>'; //Display File Size echo 'File Size: '.$file->getSize(); echo '<br>'; //Display File Mime Type echo 'File Mime Type: '.$file->getMimeType(); //Move Uploaded File $destinationPath = 'uploads'; $file->move($destinationPath,$file->getClientOriginalName()); } } #-> app/Http/routes.php Route::get('/uploadfile','UploadFileController@index'); Route::post('/uploadfile','UploadFileController@showUploadFile'); 8000/uploadfile |
#-> Mailer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
SwiftMailer // The following table shows the syntax and attributes of send function − void send(string|array $view, array $data, Closure|string $callback) Parameters $view(string|array) − name of the view that contains email message $data(array) − array of data to pass to view $callback − a Closure callback which receives a message instance, allowing you to customize the recipients, subject, and other aspects of the mail message Mail::send([‘text’=>’text.view’], $data, $callback); .env MAIL_DRIVER = smtp MAIL_HOST = smtp.gmail.com MAIL_PORT = 587 MAIL_USERNAME = your-gmail-username MAIL_PASSWORD = your-application-specific-password MAIL_ENCRYPTION = tls php artisan config:cache php artisan make:controller MailController --plain app/Http/Controllers/MailController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Mail; use App\Http\Requests; use App\Http\Controllers\Controller; class MailController extends Controller { public function basic_email() { $data = array('name'=>"Virat Gandhi"); Mail::send(['text'=>'mail'], $data, function($message) { $message->to('abc@gmail.com', 'Tutorials Point')->subject ('Laravel Basic Testing Mail'); $message->from('xyz@gmail.com','Virat Gandhi'); }); echo "Basic Email Sent. Check your inbox."; } public function html_email() { $data = array('name'=>"Virat Gandhi"); Mail::send('mail', $data, function($message) { $message->to('abc@gmail.com', 'Tutorials Point')->subject ('Laravel HTML Testing Mail'); $message->from('xyz@gmail.com','Virat Gandhi'); }); echo "HTML Email Sent. Check your inbox."; } public function attachment_email() { $data = array('name'=>"Virat Gandhi"); Mail::send('mail', $data, function($message) { $message->to('abc@gmail.com', 'Tutorials Point')->subject ('Laravel Testing Mail with Attachment'); $message->attach('C:\laravel-master\laravel\public\uploads\image.png'); $message->attach('C:\laravel-master\laravel\public\uploads\test.txt'); $message->from('xyz@gmail.com','Virat Gandhi'); }); echo "Email Sent with attachment. Check your inbox."; } } resources/views/mail.blade.php <h1>Hi, {{ $name }}</h1> l<p>Sending Mail from Laravel.</p> app/Http/routes.php Route::get('sendbasicemail','MailController@basic_email'); Route::get('sendhtmlemail','MailController@html_email'); Route::get('sendattachmentemail','MailController@attachment_email'); http://localhost:8000/sendbasicemail |
#-> Ajax Controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
resources/views/message.php <html> <head> <title>Ajax Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script> function getMessage() { $.ajax({ type:'POST', url:'/getmsg', data:'_token = <?php echo csrf_token() ?>', success:function(data) { $("#msg").html(data.msg); } }); } </script> </head> <body> <div id = 'msg'>This message will be replaced using Ajax. Click the button to replace the message.</div> <?php echo Form::button('Replace Message',['onClick'=>'getMessage()']); ?> </body> </html> php artisan make:controller AjaxController --plain app/Http/Controllers/AjaxController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class AjaxController extends Controller { public function index() { $msg = "This is a simple message."; return response()->json(array('msg'=> $msg), 200); } } app/Http/routes.php Route::get('ajax',function() { return view('message'); }); Route::post('/getmsg','AjaxController@index'); Cross Site Scripting(XSS) |
Reference:
Nginx
1 2 3 4 |
server { client_max_body_size 100M; ... } |
Apache
1 |
LimitRequestBody 104857600 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php ini_set("session.auto_start", 0); require('fpdf.php'); $pdf = new FPDF(); $pdf->AddPage() $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output(); ?> <?php ob_start(); require('fpdf.php'); $pdf = new FPDF(); $pdf->AddPage() $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output(); ob_end_flush(); ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
Install Library Files * Extrac the downloaded zip archive * Copy the Smarty library files to your system. - cp -r libs /usr/local/lib/php/Smarty $> cd YOUR_DOWNLOAD_DIR $> gtar -zxvf Smarty-3.0.tar.gz $> mkdir /usr/local/lib/php/Smarty $> cp -r Smarty-3.0/libs/* /usr/local/lib/php/Smarty /usr/local/lib/php/Smarty/ debug.tpl plugins/ Smarty.class.php sysplugins/ * You will need four directories setup for Smarty to work. These files are for templates, compiled templates, cached templates and config files. You may or may not use caching or config files, but it is a good idea to set them up anyways. It is also recommended to place them outside of the web server document root. The web server PHP user will need write access to the cache and compile directories as well. In our example, the document root is /web/www.kutayzorlu.com/docs and the web server username is "nobody". We will keep our Smarty files under /web/www.kutayzorlu.com/smarty/. If you are using FTP/sFTP, your FTP software should help you with setting the file permissions. 775 means user/group = read/write, other = read. $> cd /web/www.kutayzorlu.com $> mkdir smarty $> mkdir smarty/templates $> mkdir smarty/templates_c $> mkdir smarty/cache $> mkdir smarty/configs $> chown nobody:nobody smarty/templates_c $> chown nobody:nobody smarty/cache $> chmod 775 smarty/templates_c $> chmod 775 smarty/cache # --------------------------------------------------------- $> cd /web/www.example.com/docs $> mkdir myapp $> cd myapp $> vi index.php $ vi index.php <?php // put full path to Smarty.class.php require('/usr/local/lib/php/Smarty/Smarty.class.php'); $smarty = new Smarty(); $smarty->setTemplateDir('/web/www.kutayzorlu.com/smarty/templates'); $smarty->setCompileDir('/web/www.kutayzorlu.com/smarty/templates_c'); $smarty->setCacheDir('/web/www.kutayzorlu.com/smarty/cache'); $smarty->setConfigDir('/web/www.kutayzorlu.com/smarty/configs'); $smarty->assign('name', 'Ned'); $smarty->display('index.tpl'); ?> Create Template command line $> nano /web/www.kutayzorlu.com/smarty/templates/index.tpl Edit the index.tpl file with the following: index.tpl <html> <head> <title>Smarty</title> </head> <body> Hello, {$name}! </body> </html> http://www.kutayzorlu.com/myapp/index.php in our example. You should see the text "Hello Ned!" in your browser. PHP $smarty->testInstall(); |
Reference : Smarty Web Site
Smarty-2.6.24.tar.gz | 2010-11-11 18:20 | 149K | ||
Smarty-2.6.24.zip | 2010-11-11 18:20 | 188K | ||
Smarty-2.6.25.tar.gz | 2010-11-11 18:20 | 149K | ||
Smarty-2.6.25.zip | 2010-11-11 18:20 | 188K | ||
Smarty-2.6.26.tar.gz | 2010-11-11 18:20 | 149K | ||
Smarty-2.6.26.zip | 2010-11-11 18:20 | 188K | ||
Smarty-2.6.27.tar.gz | 2012-09-25 14:43 | 151K | ||
Smarty-2.6.27.zip | 2012-09-25 14:43 | 190K | ||
Smarty-2.6.28.tar.gz | 2013-10-01 15:24 | 151K | ||
Smarty-2.6.28.zip | 2013-10-01 15:24 | 190K | ||
Smarty-3.0.0.tar.gz | 2010-11-11 21:01 | 130K | ||
Smarty-3.0.0.zip | 2010-11-11 21:01 | 191K | ||
Smarty-3.0.1.tar.gz | 2010-11-12 10:09 | 130K | ||
Smarty-3.0.1.zip | 2010-11-12 10:09 | 191K | ||
Smarty-3.0.2.tar.gz | 2010-11-12 20:26 | 130K | ||
Smarty-3.0.2.zip | 2010-11-12 20:26 | 191K | ||
Smarty-3.0.3.tar.gz | 2010-11-13 08:33 | 130K | ||
Smarty-3.0.3.zip | 2010-11-13 08:33 | 190K | ||
Smarty-3.0.4.tar.gz | 2010-11-13 14:34 | 130K | ||
Smarty-3.0.4.zip | 2010-11-13 14:34 | 190K | ||
Smarty-3.0.5.tar.gz | 2010-11-20 22:02 | 131K | ||
Smarty-3.0.5.zip | 2010-11-20 22:02 | 191K | ||
Smarty-3.0.6.tar.gz | 2010-12-13 10:54 | 132K | ||
Smarty-3.0.6.zip | 2010-12-13 10:54 | 192K | ||
Smarty-3.0.7.tar.gz | 2011-02-11 17:09 | 132K | ||
Smarty-3.0.7.zip | 2011-02-11 17:09 | 192K | ||
Smarty-3.0.8.tar.gz | 2011-06-03 15:29 | 147K | ||
Smarty-3.0.8.zip | 2011-06-03 15:29 | 206K | ||
Smarty-3.0.9.tar.gz | 2011-09-16 13:17 | 147K | ||
Smarty-3.0.9.zip | 2011-09-16 13:17 | 207K | ||
Smarty-3.0b7.tar.gz | 2010-11-11 18:20 | 127K | ||
Smarty-3.0b7.zip | 2010-11-11 18:20 | 207K | ||
Smarty-3.0b8.tar.gz | 2010-11-11 18:20 | 125K | ||
Smarty-3.0b8.zip | 2010-11-11 18:20 | 183K | ||
Smarty-3.0rc1.tar.gz | 2010-11-11 18:20 | 119K | ||
Smarty-3.0rc1.zip | 2010-11-11 18:20 | 174K | ||
Smarty-3.0rc2.tar.gz | 2010-11-11 18:20 | 122K | ||
Smarty-3.0rc2.zip | 2010-11-11 18:20 | 177K | ||
Smarty-3.0rc3.tar.gz | 2010-11-11 18:20 | 123K | ||
Smarty-3.0rc3.zip | 2010-11-11 18:20 | 178K | ||
Smarty-3.1.0.tar.gz | 2011-09-16 13:19 | 178K | ||
Smarty-3.1.0.zip | 2011-09-16 13:19 | 249K | ||
Smarty-3.1.1.tar.gz | 2011-09-23 10:19 | 184K | ||
Smarty-3.1.1.zip | 2011-09-23 10:19 | 256K | ||
Smarty-3.1.2.tar.gz | 2011-10-03 16:04 | 186K | ||
Smarty-3.1.2.zip | 2011-10-03 16:06 | 258K | ||
Smarty-3.1.3.tar.gz | 2011-10-07 12:14 | 188K | ||
Smarty-3.1.3.zip | 2011-10-07 12:14 | 259K | ||
Smarty-3.1.4.tar.gz | 2011-10-19 15:23 | 188K | ||
Smarty-3.1.4.zip | 2011-10-19 15:23 | 259K | ||
Smarty-3.1.5.tar.gz | 2011-11-14 12:56 | 191K | ||
Smarty-3.1.5.zip | 2011-11-14 12:56 | 263K | ||
Smarty-3.1.6.tar.gz | 2011-12-01 10:32 | 191K | ||
Smarty-3.1.6.zip | 2011-12-01 10:32 | 263K | ||
Smarty-3.1.7.tar.gz | 2011-12-19 17:07 | 193K | ||
Smarty-3.1.7.zip | 2011-12-19 17:07 | 265K | ||
Smarty-3.1.8.tar.gz | 2012-02-20 11:24 | 195K | ||
Smarty-3.1.8.zip | 2012-02-20 11:24 | 266K | ||
Smarty-3.1.9.tar.gz | 2012-06-08 16:35 | 197K | ||
Smarty-3.1.9.zip | 2012-06-08 16:35 | 268K | ||
Smarty-3.1.10.tar.gz | 2012-06-09 11:54 | 197K | ||
Smarty-3.1.10.zip | 2012-06-09 11:54 | 268K | ||
Smarty-3.1.11.tar.gz | 2012-06-30 17:18 | 198K | ||
Smarty-3.1.11.zip | 2012-06-30 17:18 | 269K | ||
Smarty-3.1.12.tar.gz | 2012-09-25 14:43 | 198K | ||
Smarty-3.1.12.zip | 2012-09-25 14:43 | 270K | ||
Smarty-3.1.13.tar.gz | 2013-01-15 20:00 | 199K | ||
Smarty-3.1.13.zip | 2013-01-15 20:00 | 271K | ||
Smarty-3.1.14.tar.gz | 2013-06-27 22:13 | 200K | ||
Smarty-3.1.14.zip | 2013-06-27 22:13 | 272K | ||
Smarty-3.1.15.tar.gz | 2013-10-01 15:24 | 201K | ||
Smarty-3.1.15.zip | 2013-10-01 15:24 | 272K | ||
Smarty-3.1.16.tar.gz | 2013-12-19 17:53 | 203K | ||
Smarty-3.1.16.zip | 2013-12-19 17:53 | 275K | ||
Smarty-3.1.17.tar.gz | 2014-03-12 15:57 | 204K | ||
Smarty-3.1.17.zip | 2014-03-12 15:57 | 276K | ||
Smarty-3.1.18.tar.gz | 2014-04-07 14:37 | 204K | ||
Smarty-3.1.18.zip | 2014-04-07 14:37 | 276K | ||
Smarty-3.1.19.tar.gz | 2014-07-01 01:15 | 203K | ||
Smarty-3.1.19.zip | 2014-07-01 01:15 | 276K | ||
Smarty-3.1.20.tar.gz | 2014-10-10 09:39 | 203K | ||
Smarty-3.1.20.zip | 2014-10-10 09:39 | 276K | ||
Smarty-3.1.21.tar.gz | 2014-10-18 23:30 | 203K | ||
Smarty-3.1.21.zip | 2014-10-18 23:30 | 276K | ||
Smarty-3.1rc1.tar.gz | 2011-06-27 12:01 | 178K | ||
Smarty-3.1rc1.zip | 2011-06-27 12:01 | 249K | ||
Smarty-stable.tar.gz | 2014-10-18 23:30 | 203K | ||
Smarty-stable.zip | 2014-10-18 23:30 | 276K | ||
SmartyTrademark.pdf | 2010-11-11 18:20 | 65K | ||
docs/ | 2013-06-27 22:13 | – | ||
sampleapp.zip | 2011-11-22 15:41 | 5.3K | ||
|
# apt-get install php5-gd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libgd2-xpm Suggested packages: libgd-tools The following packages will be REMOVED: libgd2-noxpm The following NEW packages will be installed: libgd2-xpm php5-gd 0 upgraded, 2 newly installed, 1 to remove and 7 not upgraded. Need to get 270 kB of archives. After this operation, 176 kB of additional disk space will be used. Do you want to continue [Y/n]? y Get:1 http://debian.osuosl.org/debian/ squeeze/main libgd2-xpm amd64 2.0.36~rc1~dfsg-5 [231 kB] Get:2 http://security.debian.org/ squeeze/updates/main php5-gd amd64 5.3.3-7+squeeze9 [39.1 kB] Fetched 270 kB in 2s (124 kB/s) dpkg: libgd2-noxpm: dependency problems, but removing anyway as you requested: libgvc5 depends on libgd2-noxpm (>= 2.0.36~rc1~dfsg) | libgd2-xpm (>= 2.0.36~rc1~dfsg); however: Package libgd2-noxpm is to be removed. Package libgd2-xpm is not installed. (Reading database ... 206928 files and directories currently installed.) Removing libgd2-noxpm ... Selecting previously deselected package libgd2-xpm. (Reading database ... 206919 files and directories currently installed.) Unpacking libgd2-xpm (from .../libgd2-xpm_2.0.36~rc1~dfsg-5_amd64.deb) ... Setting up libgd2-xpm (2.0.36~rc1~dfsg-5) ... Selecting previously deselected package php5-gd. (Reading database ... 206930 files and directories currently installed.) Unpacking php5-gd (from .../php5-gd_5.3.3-7+squeeze9_amd64.deb) ... Processing triggers for libapache2-mod-php5 ... Reloading web server config: apache2. Setting up php5-gd (5.3.3-7+squeeze9) ... |
Proof that ;
$ php5 -m | grep -i gd