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
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 {
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(),
));
}
}
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.
|
*/