示例#1
0
文件: Form.php 项目: yolao/micromvc
 public function run()
 {
     // Load the theme sidebar since we don't need the full page
     $this->sidebar = new \Micro\View('Sidebar');
     /**
      * A validation object is setup
      */
     $validation = new \Micro\Validation($_POST);
     $validation->field('email')->required('Please enter an email')->email('Must be a valid email');
     $validation->field('password')->required('Please enter a password');
     // Bio is optional, but if given it must be text
     $validation->field('bio')->max('Bio cannot be longer than 200 characters', 200)->plaintext('Special characters are not allowed');
     // Only two options allowed
     $validation->field('gender')->options('Please select an option', array('m', 'f'));
     /**
      * A new form object is setup (which uses the validation)
      */
     $form = new \Micro\Form($validation);
     // Create some form fields
     $form->email->wrap('p')->label('email');
     $form->password->wrap('p')->label('password')->attributes(array('type' => 'password'));
     $form->bio->wrap('div')->label('Bio Text')->textarea();
     $form->gender->wrap('p')->label('Select Gender')->select(array('m' => 'Male', 'f' => 'Female'));
     /**
      * Load a view which just prints the form
      */
     // Load the HTML form
     $view = new \Micro\View('Form/Index');
     $view->set(array('form' => $form));
     $this->content = $view;
 }
 /**
  * Save user session and render the final layout template
  */
 public function send()
 {
     \Micro\Session::save();
     headers_sent() or header('Content-Type: text/html; charset=utf-8');
     $layout = new \Micro\View($this->template);
     $layout->set((array) $this);
     print $layout;
     $layout = NULL;
     if (config()->debug_mode) {
         print new \Micro\View('System/Debug');
     }
 }
// Extension of all PHP files
define('EXT', '.php');
// Directory separator (Unix-Style works on all OS)
define('DS', '/');
// Absolute path to the system folder
define('SP', realpath(__DIR__) . DS);
// Is this an AJAX request?
define('AJAX_REQUEST', strtolower(getenv('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest');
// The current TLD address, scheme, and port
define('DOMAIN', (strtolower(getenv('HTTPS')) == 'on' ? 'https' : 'http') . '://' . getenv('HTTP_HOST') . (($p = getenv('SERVER_PORT')) != 80 and $p != 443 ? ":{$p}" : ''));
// The current site path
define('PATH', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH));
require SP . 'vendor/autoload' . EXT;
// Include common system functions
require SP . 'Common' . EXT;
\Micro\View::$directory = SP . 'View/';
\Micro\Cookie::$settings = config()->cookie;
// Register events
foreach (config()->events as $event => $class) {
    event($event, NULL, $class);
}
/*
if(preg_match_all('/[\-a-z]{2,}/i', getenv('HTTP_ACCEPT_LANGUAGE'), $locales))
{
	$locales = $locales[0];
}
*/
// Get locale from user agent
if (isset($_COOKIE['lang'])) {
    $preference = $_COOKIE['lang'];
} else {