建立元數據配置文件php
參考網址:css
https://docs.nextcloud.com/server/14/developer_manual/app/init.html https://docs.nextcloud.com/server/14/developer_manual/app/info.html
建立文件example/appinfo/info.xmlhtml
<?xml version="1.0"?> <info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd"> <id>example</id> <name>Example</name> <summary>Example summary</summary> <description>Example description</description> <version>1.0.0</version> <licence>agpl</licence> <author>Author</author> <category>multimedia</category> <bugs>https://github.com/nextcloud/news/issues</bugs> <dependencies> <nextcloud min-version="10"/> </dependencies> <!--navigation 應用程序的導航條目--> <navigation> <name>example</name> <route>example.index</route> <order>0</order> </navigation> </info>
這樣應用安裝目錄就能夠看到example應用了git
<?php namespace OCA\Example\Controller; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; class ExampleController extends Controller { public function __construct(string $appName, IRequest $request){ parent::__construct($appName, $request); } /** * @NoCSRFRequired * * @return DataResponse */ public function index() { return new DataResponse([ 'test' ]); } }
控制器函數註解的用處: ``` /** * @PublicPage 公共界面 * @NoCSRFRequired 不作csrf校驗 * @NoAdminRequired 不知道作啥 猜吧 * @return DataResponse */ ```
<?php namespace OCA\Example\AppInfo; use OCP\AppFramework\App; use \OCP\IContainer; use OCA\Example\Controller\ExampleController; class Application extends App { public function __construct(array $urlParams=array()){ parent::__construct('example', $urlParams); } public function register(){ $container = $this->getContainer(); /** * Controllers */ $container->registerService('Example', function(IContainer $c) { return new ExampleController( $c->query('AppName'), $c->query('Request') ); }); } }
建立應用加載和執行文件
建立文件example/appinfo/app.phpgithub
<?php $app = new \OCA\Example\AppInfo\Application(); $app->register();
建立路由
example/appinfo/routes.phpapp
<?php return [ 'routes' => [ ['name' => 'example#index', 'url' => '/', 'verb' => 'GET'] ] ];