<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                本文介紹一下CRMEB多商戶二次開發的操作流程,從創建數據庫,到實現一個完整添加數據的過程,其他更多方法實現只是路由和方法名的差異。 ### 一、創建數據庫 例如數據庫名為:eb_is_test 字段為:id,name ```sql CREATE TABLE `eb_is_test` ( `id` int(11) unsigned NOT NULL AUTO\_INCREMENT, `name` varchar(111) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ``` ### 二、創建必要文件 為了更好的管理我給這個模塊單獨增加一個test文件目錄。 1. 創建model 路徑:app/common/moel/test/IsTest.php ```php <?php namespace app\common\model\test; use app\common\model\BaseModel; class IsTest extends BaseModel { public static function tablePk(): ?string { return 'id'; } public static function tableName(): string { return 'is_test'; } } ``` 2. 創建dao文件 路徑 :app/common/dao/test/IsTestDao.php ```php <?php namespace app\common\dao\test; use app\common\dao\BaseDao; use app\common\model\test\IsTest; class IsTestDao extends BaseDao { protected function getModel(): string { return IsTest::class; } } ``` 3. 創建repoository文件 路徑:app/common/repoository/test/IsTestRepoository.php ```php <?php namespace app\common\repositories\test; use app\common\dao\test\IsTestDao; use app\common\repositories\BaseRepository; class IsTestRepository extends BaseRepository { protected $dao; public function __construct(IsTestDao $dao) { $this->dao = $dao; } } ``` 4. 創建contorller 平臺后臺的操作就創建在admin目錄,商戶創建在merchant目錄,用戶創建在 api 目錄 路徑:app/conotroller/admin/test/IsTest.php ```php <?php namespace app\controller\admin\test; use app\common\repositories\test\IsTestRepository; use crmeb\basic\BaseController; use think\App; class IsTest extends BaseController { protected $repository; public function __construct(App $app,IsTestRepository $repository) { parent::__construct($app); $this->repository = $repository; } } ``` 這樣我們的必備的幾個基礎文件就好了,以上每個文件中的方法,都是必須創建的,否則會報錯。 - controller主要是針對路由對外訪問的接口方法 - repoository就是寫一些公用的會重復利用的邏輯處理等方法 - dao針對數據庫的操作 - model定義數據表映射對象 ### 三.創建新的接口,開發功能 1. 因為是平臺功能,就在route/admin.php文件增加路由,修改路由文件后記得重啟一下swoole服務。 ```php Route::group('is_test',function(){ Route::post('create', '/create')->name('systemIsTestCreate'); })->prefix('admin.test.IsTest); ``` 2. 在controller文件中寫相對應的功能,創建方法create ```php <?php namespace app\controller\admin\test; use app\common\repositories\test\IsTestRepository; use crmeb\basic\BaseController; use think\App; class IsTest extends BaseController { protected $repository; public function __construct(App $app,IsTestRepository $repository) { parent::__construct($app); $this->repository = $repository; } public function create() { $data = $this->request->params(['name']); $this->repository->create($data); return app('json')->success('添加成功'); } } ``` 這樣我們的一個添加數據的功能就完成了,當然如果有更多數據和邏輯需要處理,就可以在IsTestRepository 這個文件中創建一個create()方法,然后做想相對應的處理,比如把name存儲為json字符串 ```php <?php namespace app\common\repositories\test; use app\common\dao\test\IsTestDao; use app\common\repositories\BaseRepository; class IsTestRepository extends BaseRepository { protected $dao; public function __construct(IsTestDao $dao) { $this->dao = $dao; } public function create($data) { $data = [ 'name' => json_encode($data) ]; $this->dao->create($data); } } ``` 如果需要調用別的控制器的方法可以是用make方法,例如想在添加的時候調用user表查看數據 ```php <?php namespace app\common\repositories\test; use app\common\dao\test\IsTestDao; use app\common\repositories\BaseRepository; use app\common\repositories\user\UserRepository; class IsTestRepository extends BaseRepository { protected $dao; public function __construct(IsTestDao $dao) { $this->dao = $dao; } public function create($data) { //$user = app()->make(UserRepository::class)->get(1); //此處方法和上面一行的寫法一致,只是這樣寫可以不用重復make $make = app()->make(UserRepository::class); $user = $make->get(1); $data = [ 'name' => json_encode($data) ]; $this->dao->create($data); } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看