Refactored Form.
This commit is contained in:
parent
1fdf9a7ab1
commit
cfe93434ad
45 changed files with 58 additions and 83 deletions
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\Form\FieldSet;
|
||||
|
||||
class CheckboxGroup extends FieldSet
|
||||
{
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\Form\Input;
|
||||
|
||||
class Hidden extends Input
|
||||
{
|
||||
}
|
||||
|
|
@ -4,10 +4,6 @@ namespace PHPCensor;
|
|||
|
||||
use Symfony\Component\Yaml\Parser as YamlParser;
|
||||
|
||||
if (!defined('B8_PATH')) {
|
||||
define('B8_PATH', dirname(__DIR__) . '/B8Framework/');
|
||||
}
|
||||
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
use b8\Form;
|
||||
use PHPCensor\Form;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\Http\Response\RedirectResponse;
|
||||
use PHPCensor\Model\ProjectGroup;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use PHPCensor\Exception\HttpException\NotFoundException;
|
||||
use b8\Form;
|
||||
use PHPCensor\Form;
|
||||
use JasonGrimes\Paginator;
|
||||
use PHPCensor;
|
||||
use PHPCensor\BuildFactory;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
use PHPCensor\Helper\Email;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Controller;
|
||||
|
|
@ -117,42 +116,42 @@ class SessionController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
$form = new b8\Form();
|
||||
$form = new \PHPCensor\Form();
|
||||
$form->setMethod('POST');
|
||||
$form->setAction(APP_URL . 'session/login');
|
||||
|
||||
$email = new b8\Form\Element\Text('email');
|
||||
$email = new \PHPCensor\Form\Element\Text('email');
|
||||
$email->setLabel(Lang::get('login'));
|
||||
$email->setRequired(true);
|
||||
$email->setContainerClass('form-group');
|
||||
$email->setClass('form-control');
|
||||
$form->addField($email);
|
||||
|
||||
$pwd = new b8\Form\Element\Password('password');
|
||||
$pwd = new \PHPCensor\Form\Element\Password('password');
|
||||
$pwd->setLabel(Lang::get('password'));
|
||||
$pwd->setRequired(true);
|
||||
$pwd->setContainerClass('form-group');
|
||||
$pwd->setClass('form-control');
|
||||
$form->addField($pwd);
|
||||
|
||||
$remember = b8\Form\Element\Checkbox::create('remember_me', Lang::get('remember_me'), false);
|
||||
$remember = \PHPCensor\Form\Element\Checkbox::create('remember_me', Lang::get('remember_me'), false);
|
||||
$remember->setContainerClass('form-group');
|
||||
$remember->setCheckedValue(1);
|
||||
$remember->setValue(0);
|
||||
$form->addField($remember);
|
||||
|
||||
$pwd = new b8\Form\Element\Submit();
|
||||
$pwd = new \PHPCensor\Form\Element\Submit();
|
||||
$pwd->setValue(Lang::get('log_in'));
|
||||
$pwd->setClass('btn-success');
|
||||
$form->addField($pwd);
|
||||
|
||||
$tokenValue = $this->generateToken();
|
||||
$_SESSION['login_token'] = $tokenValue;
|
||||
$token = new b8\Form\Element\Hidden('token');
|
||||
$token = new \PHPCensor\Form\Element\Hidden('token');
|
||||
$token->setValue($tokenValue);
|
||||
$form->addField($token);
|
||||
|
||||
$this->view->form = $form->render();
|
||||
$this->view->form = $form->render();
|
||||
$this->view->failed = $isLoginFailure;
|
||||
|
||||
return $this->view->render();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace PHPCensor\Controller;
|
|||
|
||||
use PHPCensor\Config;
|
||||
use PHPCensor\Exception\HttpException\NotFoundException;
|
||||
use b8\Form;
|
||||
use PHPCensor\Form;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Http\Response\RedirectResponse;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace b8;
|
||||
namespace PHPCensor;
|
||||
|
||||
use b8\Form\FieldSet;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Form\FieldSet;
|
||||
|
||||
class Form extends FieldSet
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form;
|
||||
namespace PHPCensor\Form;
|
||||
|
||||
class ControlGroup extends FieldSet
|
||||
{
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form;
|
||||
namespace PHPCensor\Form;
|
||||
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Config;
|
||||
|
||||
abstract class Element
|
||||
{
|
||||
|
|
@ -168,7 +167,7 @@ abstract class Element
|
|||
*/
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
$viewPath = Config::getInstance()->get('b8.view.path');
|
||||
$viewPath = SRC_DIR . 'View/';
|
||||
|
||||
if (is_null($viewFile)) {
|
||||
$class = explode('\\', get_called_class());
|
||||
|
|
@ -178,7 +177,7 @@ abstract class Element
|
|||
if (file_exists($viewPath . 'Form/' . $viewFile . '.phtml')) {
|
||||
$view = new View('Form/' . $viewFile);
|
||||
} else {
|
||||
$view = new View($viewFile, B8_PATH . 'Form/View/');
|
||||
$view = new View($viewFile, SRC_DIR . 'Form/View/');
|
||||
}
|
||||
|
||||
$view->name = $this->getName();
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use b8\Form\Input;
|
||||
use PHPCensor\Form\Input;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Button extends Input
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
use b8\Form\Input;
|
||||
use PHPCensor\Form\Input;
|
||||
|
||||
class Checkbox extends Input
|
||||
{
|
||||
9
src/PHPCensor/Form/Element/CheckboxGroup.php
Normal file
9
src/PHPCensor/Form/Element/CheckboxGroup.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\Form\FieldSet;
|
||||
|
||||
class CheckboxGroup extends FieldSet
|
||||
{
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
9
src/PHPCensor/Form/Element/Hidden.php
Normal file
9
src/PHPCensor/Form/Element/Hidden.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\Form\Input;
|
||||
|
||||
class Hidden extends Input
|
||||
{
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
class Radio extends Select
|
||||
{
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
use b8\Form\Input;
|
||||
use PHPCensor\Form\Input;
|
||||
|
||||
class Select extends Input
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use b8\Form\Input;
|
||||
use PHPCensor\Form\Input;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Text extends Input
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
namespace PHPCensor\Form\Element;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form;
|
||||
namespace PHPCensor\Form;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form;
|
||||
namespace PHPCensor\Form;
|
||||
|
||||
use PHPCensor\View;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?php if (!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
<?php if (!($parent instanceof \PHPCensor\Form\Element\CheckboxGroup)): ?>
|
||||
<div class="control-group <?= $containerClass ?> <?= (isset($error) ? 'error' : ''); ?>">
|
||||
<div class="controls">
|
||||
<div class="checkbox">
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?= $error; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
<?php if (!($parent instanceof \PHPCensor\Form\Element\CheckboxGroup)): ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -28,7 +28,7 @@ class View
|
|||
|
||||
protected static function getViewFile($file, $path = null)
|
||||
{
|
||||
$viewPath = is_null($path) ? Config::getInstance()->get('b8.view.path') : $path;
|
||||
$viewPath = is_null($path) ? (SRC_DIR . 'View/') : $path;
|
||||
$fullPath = $viewPath . $file . '.' . static::$extension;
|
||||
|
||||
return $fullPath;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue