Giter Club home page Giter Club logo

prototurk-mvc's Introduction

prototurk-mvc

Bu çatı, prototurk için videolu eğitimlerde hazırlanmaktadır. Henüz tamamlanmadı, bir şeyler söylemek için çok erken ancak tamamlandığı kadarıyla dökümanlamak gerektiğini düşünerek başlıyoruz.

Kurulum

Repoyu bilgisayarınıza klonlayın.

git clone https://github.com/tayfunerbilen/prototurk-mvc.git prototurk-mvc

Gerekli bağımlılıkları ve ayarları yükleyin

composer install && composer update

.env.example dosyasını .env adıyla kopyalayın ve içindeki bilgileri kendinize göre doldurun

BASE_PATH=/prototurk-mvc

Rota - Route

En temel olarak bir rota şöyle tanımlanır

Route::get('/', function(){
    return 'homepage';
});

Rota Metodları

Şu an için sadece get() ve post() olsa da zamanla çoğalacak.

Route::get($uri, $callback);
Route::post($uri, $callback);

Parametreli Rotalar

Route::get('user/:id/:url', function($userId, $userUrl){
    return 'User id = ' . $userId . '<br> User url = ' . $userUrl;
});

name() Metodu

Rotalarınızı adlandırarak daha sonra ilgili isimle url'lerinizi oluşturabilirsiniz.

Route::get('/user/:id', function($id){
    //
})->name('user');

echo route('user', ['id' => 5]);
# /user/5

prefix() ve group() Metodları

Belli bir önek ile rotalarınızı gruplayabilirsiniz. Örneğin admin/ altındaki tüm rotalarınızı tek bir grupta toplayabilirsiniz.

Route::prefix('/admin')->group(function(){
    Route::get('/?', function(){
        # /admin ile eşleşir
    });
    Route::get('/users', function(){
        # /admin/users ile eşleşir
    });
});

where() Metodu

Özel parametre belirtmek için bu metodu kullanabilirsiniz.

# /@tayfunerbilen
Route::get('/@:username', function($username){
    return 'Üye = ' . $username;
})->where('username', '[a-z]+');

Bir başka örnek

# /search/kelime
Route::get('/search/:keyword', function($keyword){
    return 'Aranan kelime = ' . rawurldecode($keyword);
})->where('keyword', '.*');

redirect() Metodu

Gelen bir isteği başka bir rotaya yönlendirmek için kullanabilirsiniz. Örneğin;

Route::redirect('/php-dersleri', '/php', 301);

Controller ile kullanımı

Route::get('/', 'Home@index');
# App/Controllers/Home.php altında index metodunu çağırır

Yardımcı Fonksiyonlar

Projenin genelinde global olarak kullanileceğiniz yardımcı fonksiyonlar.

view($name, $data = []);
model($name);
route($name, $params = []);
url($name, $params = []);

prototurk-mvc's People

Contributors

tayfunerbilen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.