## 控制器定義
控制器文件通常放在`插件路徑/inc/module`下面,類名和文件名保持大小寫一致,并采用駝峰命名(首字母大寫)。
一個典型的控制器類定義如下:
~~~
// +----------------------------------------------------------------------
// | onegow [ WE CAN DO IT MORE SIMPLE]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 http://onegow.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: mrye 55585190@qq.com
// +----------------------------------------------------------------------
namespace inc\mobile;
class Index extends Base
{
/**
* 前臺首頁
*/
public function index()
{
$this->view();
}
}
~~~
> 為了插件編碼的統一規范,控制器類繼承插件的基類控制器`Og_testModuleSite`,不同插件繼承的類名稱可能會不一樣。
控制器類文件的實際位置是
~~~
插件路徑\inc\mobile\Index.php
~~~
訪問URL地址是(假設沒有定義路由的情況下)
~~~
http://localhost/app/index.php?i=2&c=entry&do=index&m=og_test
~~~
如果你的控制器是`HelloWorld`,并且定義如下:
~~~
<?php
// +----------------------------------------------------------------------
// | onegow [ WE CAN DO IT MORE SIMPLE]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 http://onegow.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: mrye 55585190@qq.com
// +----------------------------------------------------------------------
namespace inc\mobile;
class Index extends Base
{
/**
* 前臺首頁
*/
public function index()
{
return 'HelloWorld';
}
}
~~~