在單一安裝的Codeigniter 4中,從共用網站呼叫多個應用程式模型
P粉653045807
P粉653045807 2023-08-31 22:44:08
0
2
303
<p>如何在單一安裝的 Codeigniter 4 中從其他多應用程式網站呼叫模型? </p> <p>資料夾結構如下:</p> <pre class="brush:php;toolbar:false;">- WebsiteFolder -- Site1 --- app --- public --- tests --- writeable (.env, spark and other file) -- Site2 --- app --- public --- tests --- writeable (.env, spark and other file) -- system</pre> <p>這是我的範例程式碼:</p> <p><strong>在站 1</strong></p> <hr /> <p><strong>Constants.php</strong> 我已經定義了一個根目錄來定位 site2。 </p> <pre class="brush:php;toolbar:false;">define('ROOTSOURCE', dirname(__DIR__,3) . '\site2');</pre> <p>此回傳:</p> <p><em>E:\Project\website\site2</em></p> <p><strong>Autoload.php</strong></p> <p>我已經設定了 PSR4。 </p> <pre class="brush:php;toolbar:false;">public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', 'Source\Models' => ROOTSOURCE . '/app/Models/' ];</pre> <p>然後我執行 SPARK 指令:</p> <pre class="brush:php;toolbar:false;">php spark namespaces</pre> <p>並回傳</p> <pre class="brush:php;toolbar:false;"> --------------- ------------------ -------------------------------------------------- --------------------- -------- | Namespace | Path | Found? | --------------- ----------------------------------- -------------------------------------------------- ---- -------- | CodeIgniter | E:\Project\DennisLiu\website\system | Yes | | App | E:\Project\DennisLiu\website\site1\app | Yes | | Config | E:\Project\DennisLiu\website\site1\app\Config | Yes | | Source\Models | E:\Project\DennisLiu\website\site2\app\Models | Yes | --------------- ----------------------------------- -------------------------------------------------- ---- -------- </pre> <p>然後找到命名空間<strong>Source\Models</strong>。到目前為止一切都還好。</p> <p>控制器=> <strong>Home.php</strong></p> <pre class="brush:php;toolbar:false;">namespace App\Controllers; use Source\Models; class Home extends BaseController { public function index() { $setting = new \Source\Models\Setting(); return view('welcome_message'); }</pre> <p>當我運行控制器時,我得到:</p> <blockquote> <p><strong>找不到類別「Source\Models\Setting」</strong></p> </blockquote> <p>下一步,</p> <p><strong>在遺址2</strong></p> <p>我在 Site2 模型資料夾中有模型<strong>「設定」</strong>。 </p> <p><strong>注意事項:</strong></p> <p>站點 2 中的一切都運作正常。 </p> <p>我的問題是我收到的錯誤「未找到類別<strong>「Source\Models\Setting」」</strong>在單一應用程式安裝codeigniter 4 中呼叫網站2 模型的正確設定是什麼? 。 < /p> <p><strong>注意事項:</strong> 這是兩個網站的單一安裝 codeigniter 4。我共享了系統資料夾。 </p>
P粉653045807
P粉653045807

全部回覆(2)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!