03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

File-Based CMS 326<br />

.<br />

This was extracted from app/routes.php.<br />

These are quite a few files, so let’s go over them individually:<br />

1. The first file is the main admin layout template. Every page in the admin area should be<br />

rendered within this layout template. As you can see, we’ve linked the jQuery and Bootstrap<br />

assets to provide some styling and interactive functionality to the admin area.<br />

2. The second file is the main admin navigation template. This will also be present on every page<br />

in the admin area, though it’s better to include it in the main layout template than to clutter<br />

the main layout template with secondary markup.<br />

3. The third file is a sub-navigation template, only present in the pages concerning layouts.<br />

4. The fourth file is the layout index (or listing) page. It includes the sub-navigation and renders<br />

a table row for each layout file it finds. If none can be found, it will present a cheeky message<br />

for the user to add one.<br />

5. Finally we add the index route to the routes.php file. At this point, the page should be visible<br />

via the browser. As there aren’t any layout files yet, you should see the cheeky message<br />

instead.<br />

Let’s move onto the layout add page:<br />

1 public function addAction()<br />

2 {<br />

3 if (Input::has("save"))<br />

4 {<br />

5 $validator = Validator::make(Input::all(), [<br />

6 "name" => "required|add",<br />

7 "code" => "required"<br />

8 ]);<br />

9<br />

10 if ($validator->fails())<br />

11 {<br />

12 return Redirect::route("admin/layout/add")<br />

13 ->withInput()<br />

14 ->withErrors($validator);<br />

15 }<br />

16<br />

17 $meta = "<br />

18 title = " . Input::get("title") . "<br />

19 description = " . Input::get("description") . "

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!