ホームページ > バックエンド開発 > PHPチュートリアル > OpenCart に関する小さな提案

OpenCart に関する小さな提案

WBOY
リリース: 2016-06-13 12:27:57
オリジナル
976 人が閲覧しました

OpenCart についての小さな提案

OpenCart は古いオープンソースの無料 B2C 電子商取引システムです。最近、github でホストされているそのプロジェクトを観察しましたが、今でも非常に活発で、毎日バグが報告されていることがわかりました。

予備的な確認では、バックグラウンドで複数のストアの管理をサポートしており、同じ商品でも異なるストアでは異なる価格を設定でき、ストア間で異なるドメイン名をバインドできることがわかります。ここはかなりユニークな場所です。

しかし、そのコードを見ると、何年にもわたってほとんど変更されておらず、コードの役割分担に進化の感覚がないことがわかりました。

言語、リンク、現在のパスなど、ビューによって構築されるべき大量のデータは、

フロントエンドのログイン ページと同様に、コントローラーに配置されます。 :

<code class="sourceCode php"><span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;breadcrumbs&#39;</span><span class="ot">]</span> = <span class="fu">array</span><span class="ot">();</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;breadcrumbs&#39;</span><span class="ot">][]</span> = <span class="fu">array</span><span class="ot">(</span>            <span class="st">&#39;text&#39;</span> => <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_home&#39;</span><span class="ot">),</span>            <span class="st">&#39;href&#39;</span> => <span class="kw">$this</span>->url-><span class="fu">link</span><span class="ot">(</span><span class="st">&#39;common/home&#39;</span><span class="ot">)</span>        <span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;breadcrumbs&#39;</span><span class="ot">][]</span> = <span class="fu">array</span><span class="ot">(</span>            <span class="st">&#39;text&#39;</span> => <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_account&#39;</span><span class="ot">),</span>            <span class="st">&#39;href&#39;</span> => <span class="kw">$this</span>->url-><span class="fu">link</span><span class="ot">(</span><span class="st">&#39;account/account&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span><span class="ot">,</span> <span class="st">&#39;SSL&#39;</span><span class="ot">)</span>        <span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;breadcrumbs&#39;</span><span class="ot">][]</span> = <span class="fu">array</span><span class="ot">(</span>            <span class="st">&#39;text&#39;</span> => <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_login&#39;</span><span class="ot">),</span>            <span class="st">&#39;href&#39;</span> => <span class="kw">$this</span>->url-><span class="fu">link</span><span class="ot">(</span><span class="st">&#39;account/login&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span><span class="ot">,</span> <span class="st">&#39;SSL&#39;</span><span class="ot">)</span>        <span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;heading_title&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;heading_title&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;text_new_customer&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_new_customer&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;text_register&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_register&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;text_register_account&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_register_account&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;text_returning_customer&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_returning_customer&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;text_i_am_returning_customer&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_i_am_returning_customer&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;text_forgotten&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;text_forgotten&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;entry_email&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;entry_email&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;entry_password&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;entry_password&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;button_continue&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;button_continue&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;button_login&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->language->get<span class="ot">(</span><span class="st">&#39;button_login&#39;</span><span class="ot">);</span>        <span class="kw">if</span> <span class="ot">(</span><span class="fu">isset</span><span class="ot">(</span><span class="kw">$this</span>->error<span class="ot">[</span><span class="st">&#39;warning&#39;</span><span class="ot">]))</span> {            <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;error_warning&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->error<span class="ot">[</span><span class="st">&#39;warning&#39;</span><span class="ot">];</span>        } <span class="kw">else</span> {            <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;error_warning&#39;</span><span class="ot">]</span> = <span class="st">&#39;&#39;</span><span class="ot">;</span>        }        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;action&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->url-><span class="fu">link</span><span class="ot">(</span><span class="st">&#39;account/login&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span><span class="ot">,</span> <span class="st">&#39;SSL&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;register&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->url-><span class="fu">link</span><span class="ot">(</span><span class="st">&#39;account/register&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span><span class="ot">,</span> <span class="st">&#39;SSL&#39;</span><span class="ot">);</span>        <span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;forgotten&#39;</span><span class="ot">]</span> = <span class="kw">$this</span>->url-><span class="fu">link</span><span class="ot">(</span><span class="st">&#39;account/forgotten&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span><span class="ot">,</span> <span class="st">&#39;SSL&#39;</span><span class="ot">);</span></code>
ログイン後にコピー

は実際には、既存のフレームワーク機能の下ではビュー ファイルに配置できます。

ビュー ファイルの先頭:

<code class="sourceCode php"><span class="kw"><?php</span><span class="kw">$lang</span> = <span class="kw">$this</span>->registry->get<span class="ot">(</span><span class="st">&#39;language&#39;</span><span class="ot">);</span><span class="co">//加载语言包管理对象</span><span class="kw">$url</span> = <span class="kw">$this</span>->registry->get<span class="ot">(</span><span class="st">&#39;url&#39;</span><span class="ot">);</span><span class="co">//加载url对象</span><span class="kw">$this</span>->language<span class="ot">(</span><span class="st">&#39;common/footer&#39;</span><span class="ot">);</span><span class="co">//载入语言包</span><span class="kw">?></span><footer>  <div <span class="kw">class</span>=<span class="st">"container"</span>>    <div <span class="kw">class</span>=<span class="st">"row"</span>>      <<span class="ot">?</span>php <span class="kw">if</span> <span class="ot">(</span><span class="kw">$informations</span><span class="ot">)</span> { <span class="kw">?></span>      <div <span class="kw">class</span>=<span class="st">"col-sm-3"</span>>        <h5><<span class="ot">?</span>php <span class="fu">echo</span> <span class="kw">$lang</span>->get<span class="ot">(</span><span class="st">&#39;text_information&#39;</span><span class="ot">);</span> <span class="kw">?></span></h5>        <ul <span class="kw">class</span>=<span class="st">"list-unstyled"</span>>          <<span class="ot">?</span>php <span class="kw">foreach</span> <span class="ot">(</span><span class="kw">$informations</span> <span class="kw">as</span> <span class="kw">$information</span><span class="ot">)</span> { <span class="kw">?></span>          <li><a href=<span class="st">"<?php echo </span><span class="kw">$information</span><span class="st">[&#39;href&#39;]; ?>"</span>><<span class="ot">?</span>php <span class="fu">echo</span> <span class="kw">$information</span><span class="ot">[</span><span class="st">&#39;title&#39;</span><span class="ot">];</span> <span class="kw">?></span></a></li>          <<span class="ot">?</span>php } <span class="kw">?></span>        </ul>      </div>      <<span class="ot">?</span>php } <span class="kw">?></span></code>
ログイン後にコピー

このようにして、コントローラーはそのような退屈なことを心配する必要がなくなり、ビジネスに集中できますロジックとコア データと呼ばれます。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート