thinkPHP,thinkphp 插件

 2023-11-19 阅读 20 评论 0

摘要:1.切換到項目根目錄,使用composer require 5ini99/think-addons:dev-master命令安裝thinkphp插件 ? 如果是root用戶或是管理員執行的話會有提示 ? 等一下,會有這個提示 ?? thinkPHP??這就表示下好了,然后訪問tp5,會在根目錄生成addons文件夾

1.切換到項目根目錄,使用composer require 5ini99/think-addons:dev-master命令安裝thinkphp插件

? 如果是root用戶或是管理員執行的話會有提示

? 等一下,會有這個提示

??

thinkPHP??這就表示下好了,然后訪問tp5,會在根目錄生成addons文件夾(如果tp5目錄沒有權限的話需要改變權限)

?編輯application/extra/addons.php

? ??

? 在addons文件新建test文件夾,在test下新建Test.php

<?php
namespace addons\test;    // 注意命名空間規范use think\Addons;/*** 插件測試* @author byron sampson*/
class Test extends Addons    // 需繼承think\addons\Addons類
{// 該插件的基礎信息 也可以單獨配置在info.ini中public $info = ['name' => 'test',    // 插件標識'title' => '插件測試',    // 插件名稱'description' => 'tp5插件測試',    // 插件簡介'status' => 0,    // 狀態'author' => 'byron sampson','version' => '0.1'];/*** 插件安裝方法* @return bool*/public function install(){// return true;
    }/*** 插件卸載方法* @return bool*/public function uninstall(){// return true;
    }/*** 實現的testhook鉤子方法* @return mixed*/public function testhook($param){// 調用鉤子時候的參數信息// print_r($param);// 當前插件的配置信息,配置信息存在當前目錄的config.php文件中,見下方// print_r($this->getConfig());// 可以返回模板,模板文件默認讀取的為插件目錄中的文件。模板名不能為空!//return $this->fetch('info');echo "這里是鉤子調用的方法";}}
View Code

?

thinkphp官網??在test下新建config.php ,info.ini 可以不寫內容

?從項目的模板中訪問插件,{:hook('testhook')};

?

vue thinkphp?也可以在插件新建controller目錄,用法與tp5的一樣,目錄下面創建Index控制器

從項目中需要使用addon_url()訪問項目

? index.html內容

thinkphp6插件化開發??

訪問點擊鏈接

?

轉載于:https://www.cnblogs.com/jint-php7/p/9158865.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/179503.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息