PHP code example of chenqd / yii2-presenter

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

    

chenqd / yii2-presenter example snippets


use chenqd\presenter\PresentableTrait;

class User {

    use PresentableTrait;
    public function presenterMap()
    {
        return [
            'default' => UserPresenter::class,
            'api' => UserPresenter::class,
        ];
    }
    
    public $first = 'php';
    public $last = 'world';
}

//advance模板: common/config/main.php
//basic模板: config/console.php
return [
     //...其它配置
    'controllerMap' => [
        'presenter'=>\chenqd\presenter\PresenterController::class,
    ],
    //...其它配置
];

'controllerMap' => [
    'presenter' => [
        'class' => \chenqd\presenter\PresenterController::class,
        'base_path' => '@common/models',
        'namespace' => 'common\models',
    ],
],

    use chenqd\presenter\BasePresenter;
    
    /**
    * @mixin \app\models\User
    * @property \app\models\User $entity
    */
    class UserPresenter extends BasePresenter {
    
        public function fullName()
        {
            return $this->first . ' ' . $this->last;
        }
        
        public function first()
        {
            return ucfirst($this->entity->first);
        }
    
    }

<h1>hello <?= $user->present()->fullName 

<h1>hello <?= $user->present()->fullName