PHP code example of coderabbi / virtuoso

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

    

coderabbi / virtuoso example snippets

 php
View::composer('profile', function($view)
{
	$view->with('count', User::count());
}
 php
 namespace My\Project\Name\Space;

class UserCountComposer
{

	public function compose($view)
	{
		$view->with('count', User::count());
	}

}
 php
View::composer('profile', 'UserCountComposer');
 php
 namespace My\Project\Name\Space;
 
use Illuminate\Support\ServiceProvider;
 
class ComposerServiceProvider 
	extends ServiceProvider 
{
 
	public function register()
  	{
    	$this->app['view']->composer('profile', 'My\Project\Name\Space\UserCountComposer');
  	}
 
}
 php
<ul>
	@foreach ($data as $datum)
		<li>{{ $datum }}</li>
	@endforeach
</ul>
 bash
php composer.phar 
 php
'providers' => array(
    'Coderabbi\Virtuoso\ComposerServiceProvider'
)
 php
'composers' => array (
)
 php
 namespace My\Project\Name\Space;

use Coderabbi\Virtuoso\Composer;

class MyFirstSimpleComposer
	implements Composer
{

	public function compose($view)
	{
		$view->with('myData', $this->getMyData());
	}
	
	private function getMyData()
	{
		// do your thing here
	}
	
}
 php
'composers' => array (
	'partials.header' => 'My\Project\Name\Space\MyFirstSimpleComposer',
)
 php
 namespace My\Project\Name\Space;

use Coderabbi\Virtuoso\CompositeComposer;

class MyFirstCompositeComposer
	extends CompositeComposer
{

	protected $composers = array(
		'MyFirstSimpleComposer',
		'MySecondSimpleComposer',
		'MyThirdSimpleComposer'
	);
	
}
 php
'composers' => array (
	'partials.header' => 'My\Project\Name\Space\MyFirstCompositeComposer',
)