ajurgensen/php-magic

phpMagic: 集成 Propel ORM 与 Bootstrap,使构建页面、表单和列表变得简单

dev-master 2017-02-14 17:47 UTC

This package is not auto-updated.

Last update: 2024-09-19 10:12:23 UTC


README

phpMagic

将 Propel ORM 对象转换为 Bootstrap 表单 - 还可以构建列表和整个页面

  • 执行 XSS 安全性检查
  • 自动添加相关表
  • 根据需要添加其他表(多对多)
  • 重命名列名
  • 排除列
  • 客户端验证
  • 服务器端验证
  • 验证回调
  • 用于创建对象列表
  • 用于创建整个页面(包括认证等)

安装:composer require ajurgensen/phpMagic

使用 phpMagic 的几种方式

//Edit for User 
use \ajurgensen\phpMagic\formMagic;
if (!$userid || !$user = UserQuery::create()->findOneById($userid))
{
  $user = new User();
}
$names['UGLY_COLUM_NAME'] = 'This is a nicer name';
$options['FM_EXCLUDE'] = array ('PASSWORDHASH','UPDATED_AT','CREATED_AT');
$fm = new formMagic($user,$options,$names);
if ($fm->entitySaved)
{
    //all good, user updated - now redirect to some other page (entity is saved, etc) 
}else
{
    //Show the form
    echo $fm->html;
}

另一种方式

//Build a page with a list of objects
use \ajurgensen\phpMagic\formMagic;
use \ajurgensen\phpMagic\pageMagic;
$menu = array(
'Menu Point One' =>array('subpoint one' => '/one/one','subpoint two' => '/one/two'),
'Menu Point Two' =>array('subpoint one' => '/two/one','subpoint two' => '/two/two'));
$pm = new pageMagic('List Entities');
$pm->addMenu($menu);
$entites = EntityQuery::create()->find();
foreach($entites as &$entity)
{
    $entity->link = "/edit/entity/" . $entity->getId();
}
$options['LM_LINK'] = array('name');
$options['LM_ADDNEW'] = "/edit/entity/0";
$lm = new listMagic($entities,$options);
if ($lm->HTMLready)
{
    $pm->addHtml($lm->getHTML());
}
$pm->finalize();
}