PHP code example of etorojah / traillamp

1. Go to this page and download the library: Download etorojah/traillamp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

etorojah / traillamp example snippets


    composer 

   $router::get("/", "WelcomeController@main");

     $router::get("/", function(){
        echo "ok";
    });

   $router::get("/", "WelcomeController@main", "WelcomeMiddlewarre@main");

    $router::get("/", "WelcomeController@main", function(){
        echo "ok";
        return true;
    });

  $router::get("/about/{name}", "Controller@Main");

    $this->parameter 

    echo $this->name;

    $router::get("/about/{name}", "WelcomeController@main", function($name){
        echo $name;
        return true;
    });

    $name = $this->request["name"];


    $name = $this->method;
    //returns POST for a POST request method etc


    $file = $this->files["photo"];
    

    $this->view("welcome");

    //subfolder view
    $this->view("

    $this->view("profile", ["name" => "John", "email" => "[email protected]"]);
    

    $this->redirect("/about/me");
    

    $hash = $this->encrypt("I am Batman");
    echo $hash;
   

    $hash = $this->encrypt("I am Batman");
    $text = $this->decrypt($hash);
    echo $text;
    //returns I am Batman
    

    sendMail("[email protected]", "Greetings", "Hello to you");

    $result = loadModel('Users@get_users');

    $router::get("/accounts/{type}", "WelcomeController@main", function($type){
        if($type !== "user") {
            echo "You are not allowed to access this page";
            exit;
        }

        return true;
    });

    public function main(){
        try {
            $sql = "SELECT * FROM table_name";
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
            return $stmt->fetchAll();
            
        } 
        catch (PDOException $error) {
            die("Error in query:\n".$error->getMessage());
        }
	
    }


    $this->view('about', ['name' => 'David']);

    $result = $this->loadModel('Users@get_users');
    $this->view('about', ['users' => $result]);

    //Database schema
    $schema = new DatabaseSchema($parameters);
    $schema->migrate();


    //new Database schema
    $dbname = "db_test";
    $schema = new DatabaseSchema($dbname);
    $schema->migrate();


    //new Table schema
    $tablename = "users";
    $schema = new TableSchema($tablename, [
        "email" => ["type" => "varchar", "length" => "255"], 
        "fullname" => ["type" => "varchar", "length" => "255", "null" => true]
    ]);
    $schema->migrate();


    //dropping a database
    $schema = new ActionSchema([
        "action" => "alter", 
        "target" => "db_name",
        "target_type" => "database",
        "action_type" => "drop"
    ]);
    $schema->migrate();


    //dropping a table
    $tablename = "users";
    $schema = new ActionSchema([
        "action" => "alter", 
        "target" => $tablename,
        "target_type" => "table",
        "action_type" => "drop"
    ]);
    $schema->migrate();


    //truncate a table
    $tablename = "users";
    $schema = new ActionSchema([
        "action" => "truncate", 
        "target" => $tablename,
        "target_type" => "table"
    ]);
    $schema->migrate();


    $router::get("/migrations/", "MigrationController@main");

    $router::get("/about/{user}", "AboutController@main");
    $router::get("/profile/{id}", "ProfileController@main");
    //this may create a routing conflict

    $router::get("/about/{user}", "AboutController@main");
    $router::get("/{id}/profile", "ProfileController@main");
    //routing conflict solved

    $router::get("/about/{user}/details", "AboutController@main");
    $router::get("/profile/{id}", "ProfileController@main");
    //routing conflict solved

    create router-file admin_routes