PHP code example of lumax / luma

1. Go to this page and download the library: Download lumax/luma 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/ */

    

lumax / luma example snippets


public function profile(int $id): Response
{
    return $this->respond(`User ${id}`);
}

use Luma\Framework\Controller;
use Luma\HttpComponent;

class HelloWorldController extends LumaController
{
    /**
    * @return Response
    */
    public function sayHelloWorld(): Response
    {
        return $this->respond('Hello, world!');
    }
}

public function respondsWithJson(): Response
{
    $dataArray = [
       ...
    ];
    
    return $this->json($dataArray);
}



use Luma\Framework\LumaController;
use Luma\HttpComponent\Response;

class ExampleController extends LumaController
{
    public function index(): Response
    {
        $data = [
            'title' => 'Welcome to Luma',
            'description' => 'A minimalist PHP framework',
        ];

        return $this->render('index', $data);
    }
}

#[Schema('User')]
#[Table('tblUser')]
class User extends Aurora
{
    #[Identifier]
    #[Column('intUserId')]
    protected int $id;
    
    #[Column('strUsername')]
    private string $username;
    
    #[Column('strEmailAddress')]
    private string $emailAddress;
}

#[Schema('Core')]
#[Table('tblArticle')]
class Article extends Aurora
{
    #[Identifier]
    #[Column('intArticleId')]
    protected int $id;
    
    #[Column('strTitle')]
    private string $title;
    
    #[Column('intAuthorId')]
    private User $author;
    
    #[Column('dtmCreatedAt')]
    private \DateTimeInterface $created;
    
    /**
    * @param string $title
    * 
    * @return void
    */
    public function setTitle(string $title): void
    {
        $this->title = $title;
    }
}

// Create a new User instance. We can pass in property OR column names.
$user = User::create([
    'username' => 'Danny',
    'emailAddress' => '[email protected]',
]);

// Save the new User to the database.
$user->save();

Article::create([
    'title' => 'First Post!',
    'author' => $user,
])->save();

Article::create([
    'title' => 'Second Post!',
    'author' => $user,
])->save();

$user = User::find(1); // Danny

$article = Article::findBy('title', 'Second Post!');

$articles = Article::all();

$article = Article::getLatest();

$articleCount = Article::count();

$article = Article::findBy('title', 'First Post!');

$article->setTitle('First Post... Improved!');

$article->save();

$article = Article::find(2);

$article->delete();

// Select all columns from the Article table
$article = Article::select();

// Execute the query
$article = $article->get();

$article = Article::select('title')->get();

// Returns an Article instance as there is only one result
$article = Article::select()
    ->whereIs('title', 'Second Post!')
    ->get();

// Returns an array (Article[]) as there is more than one result
$articles = Article::select()
    ->whereNot('title', 'Does not exist!')
    ->get();

// Returns an array (Article[])
$articles = Article::select()
    ->whereIn('id', [1, 2])
    ->get();

// Returns NULL as there are no results for this query
$articles = Article::select()
    ->whereNotIn('id', [1,2])
    ->get();

$articles = Article::select()
    ->orderBy('id', 'DESC')
    ->get();

$article = Article::select()
    ->orderBy('id', 'DESC')
    ->limit(1)
    ->get();

$httpClient = new HttpClient();

// Methods also provided for POST, PUT, PATCH and DELETE
$response = $httpClient->get('/endpoint', $headersArray, $bodyString);

Debugger::log('Exception: ' . $exception->getMessage());
latte
{layout 'layout.latte'}

<h1>{$title}</h1>
<p>{$description}</p>