dariushha / zinux
一个简单、轻量但功能强大的支持MVC设计模式的框架
Requires
- php: >=5.5.8
README
一个简单、轻量但功能强大的支持MVC设计模式的框架
在这个项目中,我努力使它的使用变得非常简单。zinux的方针是约定优于配置,这使得它以最小的配置和更多的灵活性运行,您会发现它非常方便使用和开发。
还有一个示例项目和一个zinux生成器工具可用。
主题
要求
- PHP版本5.5.8或更高
> 注意:原始zinux是在PHP v5.3.10上编写和测试的,对于该产品的PHP其他版本语法/工作区兼容性没有保证。如果您的PHP版本小于v5.5.8但大于或等于v5.3.10,您可以使用zinux@3.4.6的最新版本,该版本与PHP v5.3.10兼容。但请注意,此版本不会更新到v4.0.0或更高版本的任何更改。但我们强烈建议您升级PHP版本,因为在v4.0.0或更高版本的zinux中有很多新功能和一些错误修复。
安装
有一个zinux安装器 shell脚本,它将自动下载和配置您的系统以免费使用系统中的zinux项目。
它还安装了zinux生成器工具,这是一个方便的工具,用于创建、操作并为您的zinux项目提供强大的安全性,更多信息请参阅Zinux生成器工具。
安装时,只需下载zinux安装器并将其保存到任何位置,然后运行以下命令bash /path/to/your/zinux/installer
它将完成所有设置。
Windows用户
由于技术原因,zinux生成器不支持Windows!您只需手动克隆和使用框架即可。
对此我们感到非常抱歉...
以下是对PHP开发者的建议,您不能在Windows环境中成为一名专业的PHP开发者并开发一个完整的PHP应用程序,您真的不能!也许现在是时候将您的PHP开发迁移到Linux上了。
目录结构
创建项目目录结构如下。(或者在zinux生成器工具中使用zg new PROJECT_NAME
命令)
PROJECT-ROOT |_ Modules |_ SomeModule |_ Controllers |_ Models |_ Views |_ Layout |_ Helper |_ View |_ zinux (the library) |_ public_html |_ * . . .
快速设置
考虑到上述目录结构;在您的PROJECT-ROOT/public_html/index.php文件中添加以下代码
<?php # PROJECT-ROOT/public_html/index.php defined("RUNNING_ENV") || define("RUNNING_ENV", "DEVELOPMENT"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "PRODUCTION"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "TEST"); require_once '../zinux/zinux.php'; $app = new \zinux\kernel\application\application("PROJECT-ROOT/mOdUlEs"); $app ->Startup() ->Run() ->Shutdown();
并且也在与index.php相同的目录中创建一个.htaccess文件,并添加以下代码以将请求路由到index.php。
# PROJECT-ROOT/public_html/.htaccess
RewriteEngine On
RewriteCond $1 !\.(gif|jpe?g|png|ico|js)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/$1
恭喜!您现在在PROJECT-ROOT/Modules下拥有完整的MVC魔法了!!
您可能想知道为什么文件夹的名称传递给
\zinux\kernel\application\application
考虑到大小写敏感性,与PROJECT-ROOT/Modules
不匹配!?
见路径解析器。
简单,不是吗!?
MVC实体
在zenux框架中定义了几个实体
- 模块
- 控制器
- 动作
- 模型
- 布局
- 视图
- 辅助函数
自动加载类和文件
zinux使用PSR-0命名空间约定来加载MVC实体。因此,只要MVC实体遵循PSR-0标准,zinux的自动加载器可能能够加载这些类,并且除了require_once '../zinux/zinux.php'
外,加载类不需要任何require
!
注意:类和相对文件应具有相同的名称。[不一定是大小写敏感的]
命名约定
MVC实体命名约定如下表
* 注意:辅助函数可以是类文件或函数文件,见加载辅助函数
路径解析器
在UNIX风格操作系统(例如Linux)中,目录映射是大小写敏感的,因此在开发大型项目时,我们应记住每个文件和文件夹都应按库定义的标准命名(即您不能在命名中错过一个字母)太糟糕了!
因此,我开发了一个非常快速和有效的路径解析器,它使库能够使用非大小写敏感的文件和文件夹命名风格!
注意:路径解析器类与
file_exist()
操作一样快,这是加载项目时不可避免的操作。它使用定制的快速有效的缓存系统,这使得路径解析器非常流畅!因此,您不必担心路径解析器运行时的因素!
引导
引导的一般定义
- 预启动
- 在bootstrap文件中,所有以pre_为前缀的公共方法都在预启动阶段被调用。
- 后启动
- 在bootstrap文件中,所有以post_为前缀的公共方法都在后启动阶段被调用。
应用程序引导
zinux使用(如果定义)bootstrap文件来启动项目,项目启动有两个阶段
- 预启动
- 在执行任何与应用程序相关的操作之前,zinux启动预启动方法,当然如果有定义。(参见[below](#registering-application-bootstrap)了解如何定义预启动。)
- 后启动
- 在执行应用程序之后,zinux启动后启动方法,当然如果有定义。(下面将介绍如何定义后启动。)
应用程序的bootstrap文件可以位于并引用到PROJECT-ROOT下的任何位置,我建议将您应用程序的bootstrap文件放在以下目录路径
PROJECT-ROOT |_ application |_ SomeAppBootstrap.php |_ AnotherAppBoostrap.php |_ Modules |_ zinux (the library) |_ public_html |_ * . . .
注意: zinux 支持多个应用程序引导文件。
注册应用程序引导
假设我们有一个名为 appBoostrap 的引导类,位于 PROJECT-ROOT/application 目录下,如下所示
<?php # PROJECT-ROOT/application/appBoostrap.php namespace application; class appBoostrap extends \zinux\kernel\application\applicationBootstrap { public function PRE_CHECK(\zinux\kernel\routing\request &$request) { /** * this is a pre-strap function use this on pre-bootstrap opt. * @param \zinux\kernel\routing\request $request */ } public function post_FOO(\zinux\kernel\routing\request $request) { /** * this is a post-strap function use this on post-bootstrap opt. * @param \zinux\kernel\routing\request $request */ } }
注意: 应用程序引导类应该继承自
\zinux\kernel\application\applicationBootstrap
。
通过覆盖 如何使用 中介绍的索引文件,如下所示
<?php # PROJECT-ROOT/public_html/index.php defined("RUNNING_ENV") || define("RUNNING_ENV", "DEVELOPMENT"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "PRODUCTION"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "TEST"); require_once '../zinux/zinux.php'; $app = new \zinux\kernel\application\application("PROJECT-ROOT/mOdUlEs"); $app ->Startup() /* * This part is added to previous * version of index.php */ ->SetBootstrap(new \application\appBootstrap) ->Run() ->Shutdown();
现在您的 appBootstrap 已在 zinux 中注册,并且将在启动项目时自动调用。
注意: 在 zinux 中,您不必只有一个项目引导文件,您始终可以有多个项目引导文件:(但当然我建议不要有多个项目引导文件,它可能会在应用级别造成混淆。)
$app ->Startup() /* * 1'st boostrap file */ ->SetBootstrap(new \application\appBootstrap) /* * 2'nd boostrap file */ ->SetBootstrap(new \application\anotherAppBootstrap) ->Run() ->Shutdown();
模块引导
zinux 使用引导文件(如果有,当加载模块时)来引导模块,引导文件位于以下映射中
PROJECT-ROOT |_ Modules |_ SomeModule |_ Controllers |_ Models |_ Views |_ SomeBootstrap.php *(your module bootstrap) |_ DefaultModule |_ Controllers |_ Models |_ Views |_ DefaultBootstrap.php *(your module bootstrap) |_ zinux (the library) |_ public_html |_ * . . .
在引导文件(它是一个类文件)中,有两种方法 Predispatch 和 Postdispatch
- Predispatch
- 在派发到动作方法之前运行!适用于检测语言或检查用户是否已登录等操作
- Postdispatch
- 在派发到动作方法之后运行!适用于进行数据清理或其他操作
注意: zinux 不允许为引导模块有多个引导文件。
模块引导示例
<?php namespace modules\defaultModule; class defaultBootstrap { # Predispatch method #1 public function PRE_echo(\zinux\kernel\routing\request $request) { echo "I am predispatch #1<br />"; echo "<div style='color:darkred'>"; echo "<br />You have requested:"; echo "<br />Module : ".$request->module->full_name; echo "<br />Controller : ".$request->controller->full_name; echo "<br />Action : ".$request->action->full_name; echo "<br />View : ".$request->view->full_name; echo "</div>"; } # Predispatch method #2 public function PRE_echo1(\zinux\kernel\routing\request $request) { echo "I am predispatch #2<br />"; } # Postdispatch method #1 public function POST_echo(\zinux\kernel\routing\request $request) { echo "I am postdispatch #1<br />"; } # Postdispatch method #2 public function POST_echo1(\zinux\kernel\routing\request $request) { echo "I am postdispatch #2<br />"; } # This function would never gets called beacause # It does not have 'pre_' OR 'post_' naming prefix public function FooFunc() { echo __METHOD__." will never get invoked..."; } }
与MVC实体一起工作(基础)
将变量传递到视图
可以通过以下代码将变量传递到 控制器 中的视图
# in our controller we path varibales like this $this->view->passed_from_controller = $some_value; # in our view we access variable like this echo $this->passed_from_controller;
将变量传递到布局
可以通过以下代码将变量传递到 控制器 和 视图 中的视图
# in our controller OR view we path varibales like this $this->layout->passed_from_controller_or_view = $some_value; # in our layout we access variable like this echo $this->passed_from_controller_or_view;
更改视图
可以通过以下代码在 控制器 中更改视图
# Assume that we have Layout named 'LoginView'(case-insensitve) under current module/controller # following code will change current view to 'LoginView' $this->view->SetView("Login"); # disable view(i.e loading no view only view) $this->view->SuppressView();
更改布局
可以通过以下代码在 控制器 和 视图 中更改布局
# Assume that we have Layout named 'CoolLayout'(case-insensitve) under current module # following code will change current layout to 'CoolLayout' $this->layout->SetLayout("COOL"); # disable any layouting(i.e loading no layout only view) $this->layout->SuppressLayout();
加载模型
当创建模型实例时,zinux 的自动加载器将加载模型。
不需要为模型使用 require
!
加载助手
如果需要的帮助器是类文件,可以在 任何地方 加载帮助器,只需创建该类的对象即可,zinux 的自动加载器将处理其余部分!但如果它们是函数文件,则应通过以下代码加载
# Assume that we have Helper file named 'fOoModel.php'(case-insensitve) under current module # loades fOoModel.php which is under current module ($this->request->module) # the exact use of this code is valid in # {Contoller} # {Model} # {View} # {Layout} new \zinux\kernel\mvc\helper("foo", $this->request->module); # now we can use functions in 'fOoHelper.php' file some_Function_In_fOo('Hello, world')
控制器示例
在这个示例中,我们将演示我们上面讨论的内容
让我们假设我们有一个在 目录结构 中定义的名为 SomeModule
的假设控制器。这是一个控制器示例(请注意命名空间和相对控制器路径)。
<?php # this controller locates at # PROJECT-ROOT/Modules/SomeModule/Controllers/FooController.php namespace \Modules\SomeController\Controllers; /** * * Remember that files pathes are not case sensitive * */ class FooController extends \zinux\kernel\controller\baseController { public function Initiate() { /** * Do your init stuffs here * This method will get called * just before invoking actions */ } /** * Url map to this controller : * * /some/foo/some/var?or=GET * * |OR| * * /some/foo/index/some/var?or=GET */ public function IndexAction() { # lets see that is the request's params are \zinux\kernel\utilities\debug::_var($this->request->params); /** * output: * * Array * ( * [some] => var * [or] => GET * ) * */ } /** * Url map to this controller : * * /some/foo/feed */ public function FeedAction() { # let assume that we have some data $data = some_data_generator(); # if the 'json' format is requested # i.e the uri is : # /some/foo/feed.json if($this->request->type == "json") { # we dont want any view or layout here $this->view->SuppressView(); # print out json format of data echo json_encode($data); return; } # or if the 'raw' format is requested # i.e the uri is : # /some/foo/feed.json elseif($this->request->type == "raw") { # we dont want any view or layout here $this->view->SuppressView(); # print out the raw format of $data \zinux\kernel\utilities\debug::_var($data); return; } # if was not a json request # pass data to view $this->view->some_data = $data; # set layout to feedLayout $this->layout->SetLayout("feed"); } /** * Url map to this controller : * * /some/foo/modeluse */ public function ModelUseAction() { /** * * In this action are trying to show * how to use model and helper * */ # Assume that we have a model in following path # PROJECT-ROOT/Modules/SomeModule/Models/Xoxo.php $o = \modules\SomeModule\Models\Xoxo(); # fetch some data from xoxo class $this->view->new_data = $o->get_some_data(); # test data validation if($this->view->new_data) { # Assume that we have a helper in following path # PROJECT-ROOT/Modules/SomeModules/Views/Helper/A_helper.php new \zinux\kernel\mvc\helper("a_helper", $this->request->module); # in A_helper.php we have bellow function $this->view->proc_data = proccess_data($this->view->new_data); # change the view $this->view->SetView("ValidData"); } else { throw new \zinux\kernel\exceptions\notFoundException("data not found!"); } } }
在上面的演示中,所有基本操作都已演示。因此,如果您跟上上述代码,您将100%准备好使用 zinux 库。
干杯!
高级
正如我之前提到的,zinux 的目的是约定优于配置,而在开发任何应用程序中最具挑战性的主题是 项目配置 和 数据库集成。
zinux 提供了一种非常简单灵活的方式,以绑定配置文件和数据库初始化器。
这些是可选的.
自定义路由
有时在开发中,有一个URL名称约定很好,例如,对于编辑笔记,而不是链接到 /note/edit/123
,您可以链接到 /note/123/edit
。这在URI级别实现了命名统一,例如,您也可以有 /note/123/delete
以及 ... 这比 /note/edit/123
和 /note/delete/123
更加美观和用户友好。
Zinux 使创建此类自定义路由映射变得非常简单,为此,您需要有一些类(zinux 支持多个路由类,但出于清洁项目的考虑,不建议使用多个路由类),这些类继承自 \zinux\kernel\routing\routerBootstrap
,您可以将路由器放在 PROJECT-ROOT 目录下的任何位置,我建议将它们放在靠近您的 应用程序引导 文件的 PROJECT-ROOT/application 下,这里有一个示例
<?php # PROJECT-ROOT/application/someRoutes.php namespace application; /** * This is a class to add custom-routes to route maps */ class someRoutes extends \zinux\kernel\routing\routerBootstrap { public function Fetch() { /** * Route Example For This: * /note/1234/edit/what/so/ever?nonsences=passed => /note/edit/1234/what/so/ever?nonsences=passed */ $this->addRoute("/note/$1/edit$2", "/note/edit/$1$2"); } }
它是如何工作的?
在从 someRoutes::Fetch()
调用的任何函数中,在 someRoutes
类中添加路由 $this->addRoute()
,您可以定义自定义路由。
注意:
$1
、$2
标记提供 uri 部分的顺序。
如何注册路由器
很简单!通过覆盖 如何使用 中引入的索引文件,如下所示
<?php # PROJECT-ROOT/public_html/index.php defined("RUNNING_ENV") || define("RUNNING_ENV", "DEVELOPMENT"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "PRODUCTION"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "TEST"); require_once '../zinux/zinux.php'; $app = new \zinux\kernel\application\application("PROJECT-ROOT/mOdUlEs"); $app /* * This part is added to previous * version of index.php */ ->SetRouterBootstrap(new \application\someRoutes) ->Startup() ->Run() ->Shutdown();
将自定义配置文件绑定到应用程序
在 PROJECT-ROOT/public_html/index.php
文件中创建 \zinux\kernel\application\application
实例时,您可以将 \zinux\kernel\application\baseConfigLoader
的实例传递给 Startup()。
并在您的模块中定义一个类,该类扩展了抽象类 \zinux\kernel\application\baseConfigLoader
,它将负责为您的应用程序加载配置。它可以是 ini 加载器或 XML 加载器等。
使用示例
注意: zinux 有自己的 ini 解析器,您可以使用它,也可以定义自己的配置处理器,由您决定。
通过覆盖 如何使用 中介绍的索引文件,如下所示
<?php # PROJECT-ROOT/public_html/index.php defined("RUNNING_ENV") || define("RUNNING_ENV", "DEVELOPMENT"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "PRODUCTION"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "TEST"); require_once '../zinux/zinux.php'; $app = new \zinux\kernel\application\application("PROJECT-ROOT/mOdUlEs"); $app /* * This part is added to previous * version of index.php */ # Note that this registration is OPTIONAL # you don't come up with any cache directory # the zinux will pick /tmp/zinux-cache as its cache directory ->SetCacheDirectory("/path/to/cache/dir") # setting Config iniliazer ->SetConfigIniliazer(new \zinux\kernel\utilities\iniParser("/path/to/config/file", RUNNING_ENV)) ->Startup() ->Run() ->Shutdown();
访问获取到的配置
\zinux\kernel\config\config
类获取所有已加载的配置!示例:# Assume that in out ini file we have following lines /* * config.db.host = localhost * config.db.username = USERNAME * config.db.password = PASSWORD * config.db.dbname = DB_NAME */ # output: localhost echo \zinux\kernel\application\config::GetConfig("config", "db", "host"); # output: USERNAME echo \zinux\kernel\application\config::GetConfig("config", "db", "username"); # output: PASSWORD echo \zinux\kernel\application\config::GetConfig("config", "db", "password"); # output: DB_NAME echo \zinux\kernel\application\config::GetConfig("config", "db", "dbname");
很简单,对吧?
将数据库处理器绑定到应用程序
在 PROJECT-ROOT/public_html/index.php
文件中创建 \zinux\kernel\application\application
实例时,您可以将 \zinux\kernel\application\baseInitializer
的实例作为次要参数传递给 构造函数。
并在您的模块中定义一个类,该类扩展了抽象类 \zinux\kernel\application\baseInitializer
,它将负责配置应用程序的数据库。
使用示例
<?php # file : PROJECT-ROOT/vendor/db/ActiveRecord/initializer.php namespace vendor\db\ActiveRecord; /** * php-activerecord initializer * @author dariush * @version 1.0 */ class ARInitializer extends \zinux\kernel\application\baseInitializer { public function Execute() { # Where PHPActive-record lib. is stored # location: PROJECT-ROOT/vendor/db/ActiveRecord/vendor require_once 'vendor/ActiveRecord.php'; /** * For sake of following codes, you can do them in your `appBootstrap` too! * Its much better if only invoke the php-activerecord's autoloader and let its * configurations to be done in latter at a higher level code snap. * (e.g. in your `application/appBootstrap.php`.) ActiveRecord\Config::initialize(function($cfg) { $cfg->set_model_directory('models'); $cfg->set_connections(array( 'development' => 'mysql://username:password@localhost/database_name')); }); * **/ } }
通过覆盖 如何使用 中介绍的索引文件,如下所示
<?php # PROJECT-ROOT/public_html/index.php defined("RUNNING_ENV") || define("RUNNING_ENV", "DEVELOPMENT"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "PRODUCTION"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "TEST"); require_once '../zinux/zinux.php'; $app = new \zinux\kernel\application\application("PROJECT-ROOT/mOdUlEs"); $app /* * This part is added to previous * version of index.php */ ->SetInitializer(new \vendor\db\ActiveRecord\ARInitializer()) ->Startup() ->Run() ->Shutdown();
您的应用程序配置为使用 PHP ActiveRecord 作为数据库处理程序,您可以在项目中自由使用 PHP ActiveRecord 框架。
仍然很简单,对吧?
添加插件
在 zinux 中添加插件非常简单,您只需在 PROJECT-ROOT 下的任何位置添加插件,然后无需任何注册或配置即可开始使用它!!!
什么?! 是的,您说得对!但请确保您的插件已遵循 PSR-0 标准,这在 自动加载类和文件 中进行了讨论。
实际上,zinux 将整个项目视为插件本身!!
/** * * in 'zinux/baseZinux.php' you will see the zinux * introduces the project's root directory as a plugin * to itself since the registerPlugin() considers plugins * under PROJECT-ROOT directory by passing no plugin directory * it will add the PROJECT-ROOT as a plugin! * */ # require plugin file require_once 'kernel/application/plugin.php'; # initiate a new plugin $plugin = new kernel\application\plugin(); # treat current project as a plugin $plugin->registerPlugin("PROJECT_ROOT");
简单,对吧?
注意: 在使用 第三方 库的情况下,您可能会遇到以下两种情况之一
情况 #1
在使用已应用其自己的 [PSR-0 标准](http://www.sitepoint.com/autoloading-and-the-psr-0-standard/) 的 第三方 库的情况下,您可以像下面这样将其 根目录 引入 zinux。通过覆盖 如何使用 中介绍的索引文件,如下所示
<?php # PROJECT-ROOT/public_html/index.php defined("RUNNING_ENV") || define("RUNNING_ENV", "DEVELOPMENT"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "PRODUCTION"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "TEST"); require_once '../zinux/zinux.php' $app = new \zinux\kernel\application\application("PROJECT-ROOT/mOdUlEs"); $app /* * * introducing two 'sundries' and 'FooPlug' plugin to zinux * */ # 'sundries' plugin is under "Some/Where/Under/PROJECT-ROOT/sundires" directory ->registerPlugin("sundries", "Some/Where/Under/PROJECT-ROOT/sundires") # 'FooPlug' plugin is under "Some/Where/Under/PROJECT-ROOT/FooPlug" directory ->registerPlugin("FooPlug", "Some/Where/Under/PROJECT-ROOT/FooPlug") ->Startup() ->Run() ->Shutdown();
注意: 如果第三方库没有遵循 PSR-0 标准,则必须应用下面的 情况 #2。实际上两者是相同的,但在 情况 #1 中,zinux 会为您执行 自动加载,在 情况 #2 中,您必须定义自己的 自动加载器,大多数第三方库都会这样做,您只需调用它即可。请参见以下内容。
情况 #2
在使用未应用 [PSR-0 标准](http://www.sitepoint.com/autoloading-and-the-psr-0-standard/) 且难以应用 [PSR-0 标准](http://www.sitepoint.com/autoloading-and-the-psr-0-standard/) 的第三方库的情况下,以下 提示 可能很有用!提示:如果您正在使用第三方插件,您不需要将整个插件标准化为PSR-0 标准(注意,我们在绑定数据库处理程序到应用程序中没有更改任何PHP-ActiveRecord命名空间!!)
您只需在那个插件中创建一个初始化类,该类定义了该插件的自动加载器!在绑定数据库处理程序到应用程序示例中,自动加载器在
# Where PHPActive-record lib. is stored # location: PROJECT-ROOT/vendor/db/ActiveRecord/vendor require_once 'vendor/ActiveRecord.php';
然后在应用程序运行之前调用插件自动加载器!即通过覆盖如何使用中引入的索引文件,如下所示
<?php # PROJECT-ROOT/public_html/index.php defined("RUNNING_ENV") || define("RUNNING_ENV", "DEVELOPMENT"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "PRODUCTION"); # defined("RUNNING_ENV") || define("RUNNING_ENV", "TEST"); require_once '../zinux/zinux.php' $app = new \zinux\kernel\application\application("PROJECT-ROOT/mOdUlEs"); /** * * Call the pluging initliazer here! * */ # Lets assume that we have third-party library and we wish to use it # And also we have a class `\Some\Where\In\Project\FOO_PLUGIN_INITIALIZER` # Just do class the `\Some\Where\In\Project\FOO_PLUGIN_INITIALIZER` here! $plugin_init = \Some\Where\In\Project\FOO_PLUGIN_INITIALIZER(); $plugin_init->A_Func_To_Add_Plugins_Autoloader() $app ->Startup() ->Run() ->Shutdown();
技巧
请求类型
zinux 支持请求类型,即您可以使用一个指向 NewsController 和 FeedAction 的 URI,如 /news/feed.json
,您可以根据请求类型(在这里是 json
)在 NewsController::FeedAction() 中输出数据。默认为 html
。
示例项目
您可以从 zinux-demo 下载一个演示项目。
zinux生成器工具
Zinux 生成器工具 是一个高效的工具,旨在使使用 zinux 项目比现在更加容易,并且让您在短时间内开发更多内容。
例如,只需输入以下命令,您就可以准备就绪的项目
# shortcut form: # zg n new_project zg new new_project
上述命令将创建一个包含
defaultModule
、appBootstrap
、appRoutes
、indexConroller
等等的全新项目。
或者,以下命令将在任何控制器和任何期望的模块中创建一个新的动作及其相关的视图
# shortcut form: # zg n a action_name (controller_name) (module_name) zg new action action_name (controller_name) (module_name)
有关更多信息,请参阅 Zinux 生成器项目的官方页面。
它还通过为您的项目提供强大的代码级安全来保护您的项目,这些安全措施包括设计用于加密或解密项目代码文件的强大加密/解密算法。