root/trunk/modules/forge/controllers/forge_demo.php

Revision 2314, 2.4 kB (checked in by Shadowhand, 2 months ago)

Updated demo controllers with a full class header and comments.

  • Property svn:eol-style set to LF
  • Property copyright set to Copyright (c) 2007-2008 Kohana Team
  • Property svn:keywords set to Id
Line 
1 <?php defined('SYSPATH') or die('No direct script access.');
2 /**
3  * Forge module demo controller. This controller should NOT be used in production.
4  * It is for demonstration purposes only!
5  *
6  * $Id$
7  *
8  * @package    Forge
9  * @author     Kohana Team
10  * @copyright  (c) 2007-2008 Kohana Team
11  * @license    http://kohanaphp.com/license.html
12  */
13 class Forge_demo_Controller extends Controller {
14
15     // Do not allow to run in production
16     const ALLOW_PRODUCTION = FALSE;
17
18     public function index()
19     {
20         $profiler = new Profiler;
21
22         $foods = array
23         (
24             'tacos' => array('tacos', FALSE),
25             'burgers' => array('burgers', FALSE),
26             'spaghetti' => array('spaghetti (checked)', TRUE),
27             'cookies' => array('cookies (checked)', TRUE),
28         );
29
30         $form = new Forge(NULL, 'New User');
31
32         // Create each input, following this format:
33         //
34         //   type($name)->attr(..)->attr(..);
35         //
36         $form->hidden('hideme')->value('hiddenz!');
37         $form->input('email')->label(TRUE)->rules('required|valid_email');
38         $form->input('username')->label(TRUE)->rules('required|length[5,32]');
39         $form->password('password')->label(TRUE)->rules('required|length[5,32]');
40         $form->password('confirm')->label(TRUE)->matches($form->password);
41         $form->checkbox('remember')->label('Remember Me');
42         $form->checklist('foods')->label('Favorite Foods')->options($foods)->rules('required');
43         $form->dropdown('state')->label('Home State')->options(locale_US::states())->rules('required');
44         $form->dateselect('birthday')->label(TRUE)->minutes(15)->years(1950, date('Y'));
45         $form->submit('Save');
46
47         if ($form->validate())
48         {
49             echo Kohana::debug($form->as_array());
50         }
51
52         echo $form->render();
53
54         // Using a custom template:
55         // echo $form->render('custom_view', TRUE);
56         // Inside the view access the inputs using $input_id->render(), ->label() etc
57         //
58         // To get the errors use $input_id_errors.
59         // Set the error format with $form->error_format('<div>{message}</div>');
60         // Defaults to <p class="error">{message}</p>
61         //
62         // Examples:
63         //   echo $username->render(); echo $password_errors;
64     }
65
66     public function upload()
67     {
68         $profiler = new Profiler;
69
70         $form = new Forge;
71         $form->input('hello')->label(TRUE);
72         $form->upload('file', TRUE)->label(TRUE)->rules('required|size[200KB]|allow[jpg,png,gif]');
73         $form->submit('Upload');
74
75         if ($form->validate())
76         {
77             echo Kohana::debug($form->as_array());
78         }
79
80         echo $form->render();
81     }
82
83 } // End Forge Demo Controller
84
Note: See TracBrowser for help on using the browser.