PHP code example of themonkeys / laravel-silverstripe

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

    

themonkeys / laravel-silverstripe example snippets


'providers' => array(
    'Themonkeys\Silverstripe\SilverstripeRoutingServiceProvider',
)

'aliases' => array(
    'CMS' => 'Themonkeys\Silverstripe\Silverstripe',
)

'aliases' => array(
    'L_Config'       => 'Illuminate\Support\Facades\Config',
    'L_Controller'   => 'Illuminate\Routing\Controllers\Controller',
    'L_Cookie'       => 'Illuminate\Support\Facades\Cookie',
    'L_File'         => 'Illuminate\Support\Facades\File',
    'L_Form'         => 'Illuminate\Support\Facades\Form',
    'L_Session'      => 'Illuminate\Support\Facades\Session',
    'L_Validator'    => 'Illuminate\Support\Facades\Validator',
)



use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;

class YourController extends BaseController {
    ...

    public static function postForm() {
        Input::flash();
        $validator = Validator::make(Input::all(), static::$rules);

        ...
    }
}



use Illuminate\Routing\Controller;

class BaseController extends Controller {

global $database;
$database = '';

rset('utf8');


Themonkeys\Silverstripe\Laravel::configureSilverstripe();

return array(
	'default' => 'mysql',
	'connections' => array(
		'mysql' => array(
			'driver'    => 'mysql',
			'host'      => 'localhost',
			'database'  => 'mysite',
			'username'  => 'mysite',
			'password'  => 'mysite',
			'charset'   => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix'    => '',
		),
	),
);

class Page extends SiteTree {

	private static $db = array(
	);

	private static $has_one = array(
	);

    public function PreviewLink($action = null) {
        $link = $this->RelativeLink($action);
        if (!starts_with($link, '/')) {
            $link = '/' . $link;
        }
        return $link;
    }
}

$app->redirectIfTrailingSlash();

// an ordinary Laravel route
Route::get('/', 'HomeController@showWelcome');

// a Silverstripe route
// matches any URL specified in the CMS with a page type (i.e. ClassName) of Page
Route::get_silverstripe('Page', 'PageController@showPage');

// an ordinary Laravel POST route
Route::post('/form', 'FormController@saveForm');

// a Silverstripe POST route
// matches any URL specified in the CMS with a page type (i.e. ClassName) of PageWithForm and method GET
Route::post_silverstripe('PageWithForm', 'PageController@saveForm');


use Illuminate\Support\Facades\View;

class PageController extends BaseController {

    public static function showPage() {
        return View::make('page', array(
            'model' => CMS::model(),
        ));
    }
}

<!DOCTYPE html>
<html lang="utf-8">
<head>
    <title>{{ $model->Title }}</title>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    {{ $model->MetaTags(false) }}
</head>
<body class="{{ $model->ClassName }}">

    <div class="main" role="main">
        <div class="inner typography line">
            <div class="content-container unit size3of4 lastUnit">
                <article>
                    <h1>{{ $model->Title }}</h1>
                    <div class="content">{{ ss($model->Content) }}</div>
                </article>
            </div>
        </div>
    </div>

</body>
</html>

App::before(function($request) {
    $page = CMS::model();
    if ($page && $page->Exists()) {
        View::share('model', $page);
    }
});


public static function showPage() {
    return View::make('page');
}

/*
|--------------------------------------------------------------------------
| Require The View Composers File
|--------------------------------------------------------------------------
|
| Next we will load the view composers file for the application. This gives
| us a nice separate location to store our view composers and shared view
| data definitions instead of putting them all in the main routes file.
|
*/


App::bind('\Themonkeys\Silverstripe\ContentProcessor', 'MyContentProcessor');
bash
php artisan silverstripe:build --flush
bash
php artisan silverstripe:password
sh
php artisan config:publish themonkeys/laravel-silverstripe