PHP code example of ryannielson / prez

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

    

ryannielson / prez example snippets


// app/presenters/UserPresenter.php
class UserPresenter extends RyanNielson\Prez\Presenter 
{
}

class UserPresenter extends RyanNielson\Prez\Presenter 
{
    public function fullName()
    {
        return $this->object->firstName . ' ' . $this->object->lastName;
    }
}

class UserPresenter extends RyanNielson\Prez\Presenter 
{
    // This allows us to use $this->user instead of $this->object
    protected $presents = 'user'; 

    public function fullName()
    {
        return $this->user->firstName . ' ' . $this->user->lastName;
    }
}

$user = new User;
$userPresenter = presenter($user); // Returns an instance of UserPresenter

$user = new User;
$userPresenter = presenter($user, 'AdminPresenter'); // Returns an instance of AdminPresenter

$user = new User;
$userPresenter = new UserPresenter($user);

<!-- Assuming you have a $userPresenter available in the view. -->
<h1>{{ $userPresenter->fullName() }}</h1>

class User
{
    public $name = 'Ryan';

    public function language()
    {
        return 'PHP';
    }
}

class UserPresenter extends RyanNielson\Prez\Presenter 
{
}

$userPresenter = new UserPresenter(new User);

// Since no method or property exists on presenter, these flow to the object.
$userPresenter->name; 
$userPresenter->language();