greenfly/framework

专为创意专业人士设计的快速CMF

dev-master 2016-03-15 16:22 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:59:38 UTC


README

#Greenfly 框架

这是 Greenfly 网站生成器的内核。建议您使用标准的 Greenfly 包开始,因为它可以快速创建一个项目。

文档

文档正在建设中。

安装

Composer

使用 Composer 创建一个新项目,这是推荐的途径

Composer create-project Greenfly/Greenfly

##基本用法:Greenfly 内容管理系统框架设计得易于扩展和灵活,以满足您的需求。您只需要一个包含您的页面树和 php 配置文件的 JSON 文件即可开始。每个页面可以引用一个视图文件,该文件可以使用 Twig 模板引擎,或者使用任何类的静态方法。框架附带标准内容模块,但您可以根据自己的需求进行定制,无论是扩展 Greenfly 模块系统还是使用自己的类。

###documents.json 文件 documents.json 文件是您存储网站页面列表以及您想要对它们做什么的地方。它必须遵循某种对象结构,如下所示

{

    "HTTP METHOD" : {

        "PAGE URL" :  ..

    }

}

例如,以下将生成一个可接受的 documents.json 文件。

{

    "get" : {

        "/" : "home.html",

        "/about" : {

            "renderData": {"mainClass": "sampleClass "},

            "view": "about.html"

        },

        "/:type_name/:content_name" : {

            "callback" : "Greenfly\\Modules\\Content\\Content" : "contentWithRelated",

            "config" : {

                "params" : {

                    "take" : 20

                }

                "render" : {

                    "view" : "article.html",

                    "data" : { "itemClass" : "class1 class2" }

                }

            }


        }

    }

}

上面的 documents.json 文件将生成以下页面结构

  • [yoursite.com]/ ==> 将渲染 home.html,并包含来自配置文件的任何网站变量。

  • [yoursite.com]/about ===> 渲染 about.html,包含网站变量以及 renderData JSON 对象中的条目。

  • [yoursite.com]/article/my-article ===> 调用相关类中的 contentWithRelated 方法,并传递 type_name、content_name 和 take 作为参数。它将随后传递来自数据库的附加变量以及关联的 render 属性中的数据 JSON 对象到 article.html 文件。

###site.php 配置文件 site.php 配置文件是一个 PHP 数组,在启动网站时通过 Greenfly 传递。它包含启动和正确工作框架所需的所有必要项目。有几个键是 site 必须有的才能正常工作。

$config = [

    'site' => [

        'variables' => [                                    // variables that get passed to your html template files
            'siteName' => 'My New Site',
            'siteDescription' => 'a super amazing site ,
            'siteUrl' => http://mysite.com,
            'pageTitle' => 'my awesome website',
            'metaDescription' => 'check out my new site',
            'metaKeywords' => ''
        ],
        'database' => [                                         // The database information
              'driver'    => 'mysql',
              'database'  => 'pursesbliss',
              'username'  => 'root',
              'password'  => '',
              'charset'   => 'utf8',
              'collation' => 'utf8_unicode_ci',
              'prefix'    => '',
              'host'      => 'localhost'
                          ],
        'theme_directory' => '../themes',                       // the location where you will place your template files
        'theme_cache_directory' => '../cache'                   // the cache directory
    ]
];

###public/index.php 文件

use Greenfly\App as App;

include '../vendor/autoload.php';
include '../config/site.php';

$jsonDoc = file_get_contents('../documents.json');


$app = new App($config);
$app->runDocument($jsonDoc);

###themes/standard/home.html

{{dump()}}                               // will dump all variables allowed to be used in this file

<div>
<h1>Welcome to {{siteName}}.</h1>        // will show the siteName variable

<p>{{siteDescription}} </p>             // will show the siteDescription variable

Please enjoy
</div>

###http 参数

所有 GET 和 POST 参数都会推送到类方法或渲染视图文件,可以访问。以下是一个示例。

http://mysite.com/about?cat_owner=Lary&cat_name=Killa

示例视图文件

<p>The owner of {{cat_name}} is {{cat_owner}}</p>

示例类回调方法

Class MyModule {

    public static function catOwner ($config)

    {

        $catOwner = $config['params']['cat_owner'];

        $catName = $config['params']['cat_name'];

        echo $catName . 'is owned by: ' . $catOwner . ' whom is very odd.';

    }

}

##总结 希望您喜欢使用 Greenfly。这个内容框架确实填补了我之前的空白,当时流行的 CMS 太不灵活,耗时太多,而应用框架又过于强大和功能丰富,超出了我的需求。我认为这个 CMF 并不是适合每个人或所有网站。我认为它适用于构建交互式内容网站和商业网站。如果您想创建一个重型的博客/文章网站,建议您继续使用 WordPress;如果您需要更深入的应用程序,则可以使用 Laravel 等更大的 MVC 框架。

Greenfly 是为希望快速轻松地为他们的客户提供优秀网站的专业的网页设计师和开发者设计的。