This is not the right way to create dynamic pages instead, you should use a database and keep all pages in the database. For example:
// Create pages table for dynamic pages
id | slug | title | page_content
Then create Page
Eloquent
model:
class Page extends Eloquent {
// ...
}
Then create Controller
for CRUD
, you may use a resource
controller or a normal controller, for example, normally a PageController
:
class PageController extends BaseController {
// Add methods to add, edit, delete and show pages
// create method to create new pages
// submit the form to this method
public function create()
{
$inputs = Input::all();
$page = Page::create(array(...));
}
// Show a page by slug
public function show($slug = 'home')
{
$page = page::whereSlug($slug)->first();
return View::make('pages.index')->with('page', $page);
}
}
The views/page/index.blade.php
view file:
@extends('layouts.master')
{{-- Add other parts, i.e. menu --}}
@section('content')
{{ $page->page_content }}
@stop
To show pages create a route like this:
// could be page/{slug} or only slug
Route::get('/{slug}', array('as' => 'page.show', 'uses' => 'PageController@show'));
To access a page, you may require url/link
like this:
http://example.com/home
http://example.com/about
This is a rough idea, try to implement something like this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…