PHP code example of rawebone / view-model

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

    

rawebone / view-model example snippets



namespace My\App\Views;

// src/My/App/Views/Model.php

use Rawebone\ViewModel\AbstractViewModel;

class Model extends AbstractViewModel
{
    // Define your logic/constructors here

    public function name()
    {
        return "John";
    }
}





// src/My/App/Views/Model.view.php

echo $model->name() . "\n";



$engine = new \Rawebone\ViewModel\Engine\BasicPhpEngine();
echo $engine->render(new \My\Project\Views\Model()); // John



$meta = new \Rawebone\ViewModel\MetaData\Providers\ZeptechMetaDataProvider():

$model = $meta->collateFor(new \My\Project\Views\Model());

foreach ($model as $exposed) {
    echo "Type: " . ($exposed->isProperty() ? "Property" : "Method") . "\n" .
         "Name: " . $exposed->name() . "\n" . 
         "Returns:" . $exposed->returnType() . "\n" .
         "Example: " . $exposed->example() . "\n";
}


namespace My\Project\Views;

use Rawebone\ViewModel\AbstractViewModel;

class Model extends AbstractViewModel
{
    /**
     * @vmExpose
     * @vmReturn string
     * @vmExample JOHN
     */
    public $upper;

    /**
     * @vmExpose
     * @vmReturn string
     * @vmExample John
     */
    public function name()
    {
        return "John";
    }
}