100

公式フォーラムでのいくつかのAPI呼び出しを除いて、ドキュメントがないようです。ZendフレームワークとCodeIgniterフレームワークの経験があります。OpenCartのマスターは、それを学び、最短時間でマスターするための最良の方法を私に勧めることができますか?私はすぐにそれで大きなプロジェクトをしなければなりません。

4

6 に答える 6

316

初心者向けのOpenCart1.5.X開発者クイックスタートガイド

このガイドは、PHP、OOP、およびMVCアーキテクチャにすでに精通している開発者を対象としています。

以下に、カートのカタログ側の例を示します。管理者側は、関連するセクションに記載されているビューを除いて、機能は同じです。


ライブラリを理解する

すべてのライブラリ機能には、を使用してController、Model、およびViewsからアクセスできます$this->library_name。これらはすべて/system/library/フォルダにあります。たとえば、現在のショッピングカートの商品にアクセスするには、クラスを使用する必要があります。このCartクラスには、次/system/library/cart.phpの方法でアクセスできます。$this->cart->getProducts()

よく使うアイテム

  • customer.php-顧客関連機能
  • user.php-管理ユーザー関連機能
  • cart.php-カート関連の機能
  • config.php-これからすべての設定が読み込まれます
  • url.php-URL生成機能

ルートパラメータを理解する

OpenCartのフレームワークは、クエリ文字列パラメーター内で何をロードするかを知ることに依存しておりroute=aaa/bbb/ccc、各ページで編集する必要のあるファイルを見つけるための基盤となる機能です。ほとんどのルートは実際にはaaa/bbb2つの部分としてのみ表示されるものを使用しますが、一部には3つの部分が含まれますaaa/bbb/ccc。最初の部分aaaは通常、コントローラーやテンプレートフォルダーなどの汎用フォルダー内のフォルダーに関連します。2番目の部分は通常、ファイル名に関連しており、関連する.php拡張子はありません.tpl。3番目の部分は、以下の「コントローラーについて」のセクションで説明されています。


言語を理解する

言語はサブフォルダー/catalog/language/your-languageフォルダーに保存されます。この中で、さまざまなページで使用される一般的なテキスト値your-language.phpはフォルダー内のファイルに保存されるため、カタログ側の英語の場合、値はにありますcatalog/language/english/english.php。特定のページテキストについては、ページのが必要routeになります(これは一般的に当てはまりますが、好きな言語ファイルを指定できるため、常にそうとは限りません)。たとえば、検索ページにはルートproduct/searchが含まれているため、そのページの言語固有のテキストは次の場所にcatalog/language/english/product/search.phpあります(ファイルの名前とサブフォルダーがルートの後に。が続くことに注意してください.php

コントローラに言語をロードするには、次を使用します

$this->language->load('product/search');

次に、言語ライブラリ関数を使用して、次getのような特定の言語テキストを取得できます。

$some_variable = $this->language->get('heading_title');

$_言語変数は、キーとテキスト値の配列である特別な変数を使用して言語ファイルに割り当てられます。あなたの中に/catalog/language/english/product/search.phpあなたは似たようなものを見つけるはずです

$_['heading_title']     = 'Search';

グローバル言語ファイルの値は自動的にロードされ、メソッドenglish/english.phpなしで使用できます$this->language->load


コントローラーを理解する

コントローラはに基づいてロードされ、route理解するのはかなり簡単です。コントローラは/catalog/controller/フォルダにあります。最後の例から続けると、検索ページのコントローラーは/product/search.phpこのフォルダー内にあります。が続くルート.phpが使用されていることに再度注意してください。

コントローラファイルを開くと、クラスを拡張するPascalCaseクラス名が表示さControllerControllerProductSearchます。これもルートに固有であり、Controllerその後にサブフォルダー名とファイル名が続き、拡張子は大文字になりません。大文字と小文字は実際には必要ありませんが、読みやすくするために使用することをお勧めします。クラス名は、文字と数字以外のサブフォルダーとファイル名から値を取得しないことに注意してください。アンダースコアは削除されます。

クラス内にはメソッドがあります。宣言されたクラスのメソッドはpublic、ルートを介して実行するためにアクセス可能ですが、そうでprivateはありません。デフォルトでは、標準の2つの部分からなるルート(aaa/bbb上記)では、デフォルトのindex()メソッドが呼び出されます。ルートの3番目の部分(ccc上記)が使用されている場合、代わりにこのメソッドが実行されます。たとえば、ファイルとクラスaccount/return/insertをロードし、メソッドを呼び出そうとします/catalog/controller/account/return.phpinsert


モデルを理解する

OpenCartのモデルは/catalog/model/フォルダー内にあり、ルートではなく機能に基づいてグループ化されているため、を介してコントローラーにモデルをロードする必要があります。

$this->load->model('xxx/yyy');

xxxこれにより、ファイルが。というサブフォルダーに読み込まれyyy.phpます。その後、オブジェクトを介して使用できるようになります

$this->model_xxx_yyy

publicまた、コントローラーと同様に、そのメソッドのみを呼び出すことができます。たとえば、画像のサイズを変更するには、tool/imageモデルを使用して、次のようにそのresizeメソッドを呼び出します。

$this->load->model('tool/image');
$this->model_tool_image->resize('image.png', 300, 200);

コントローラからのビューでの変数の割り当てを理解する

コントローラからビューに値を渡すには、データを$this->data変数に割り当てる必要があります。変数は、基本的にキー=>値のペアの配列です。例として

$this->data['example_var'] = 123;

ビューでこれにアクセスするのは、各キーを変数に変換するextract()メソッドに精通している場合は少し理解しやすいはずです。したがって、example_varキー$example_varはビューでそのようになり、アクセスできるようになります。


テーマを理解する

テーマはカタログ側でのみ利用可能であり、基本的にはテンプレート、スタイルシート、テーマ画像のフォルダーです。テーマフォルダーは/catalog/view/theme/、テーマ名が後に続くフォルダーに配置されます。フォルダを除いて、フォルダ名は重要ではありませdefault

管理者側は使用します(異なるテーマを許可しないため、パスから/admin/view/template/スキップします)/theme/theme-name/

テンプレートファイルはtemplate、テーマフォルダー内のフォルダーにあります。現在選択されているテーマで使用できるテンプレートがない場合は、代わりにデフォルトのフォルダーのテンプレートがフォールバックとして使用されます。つまり、テーマはごくわずかなファイルで作成でき、それでも完全に機能します。また、アップグレードが行われるときにコードの重複と問題が減少します


ビュー(テンプレート)を理解する

言語やモデルと同様に、ビューファイルは一般的にルートに関連していますが、必ずしもそうである必要はありません。カタログ側のテンプレートは、存在しない場合を/catalog/view/theme/your-theme/template/除いて通常はにあります。存在しない場合は、デフォルトのテーマのテンプレートが使用されます。上記の検索ページの例では、ファイルはproduct/search.tplです。3つの部分からなるルートの場合aaa/bbb_ccc.tpl、ハードセットのルールはありませんが、通常はインです。管理者では、ほとんどのページがこれに従います。ただし、商品リストページなどのアイテムをリストするページがcatalog/product_list.tplあり、商品編集フォームがありcatalog/product_form.tplます。繰り返しますが、これらは設定されていませんが、デフォルトのカートの標準です。

テンプレートファイルは、実際には単なる別のphpファイルですが、拡張子が.tplで、実際にはコントローラーファイルで実行されるため、コントローラーでコーディングできるすべてのものをテンプレートファイルで実行できます(ただし、絶対に必要な場合を除いて、お勧めしません)。必要)


データベースオブジェクトを理解する

クエリはを使用して実行されます

$result = $this->db->query("SELECT * FROM `" . DB_PREFIX . "table`");

DB_PREFIX名前が示すように、データベースプレフィックスが存在する場合はそれを含む定数です

$resultSELECTいくつかのプロパティを含むクエリのオブジェクトを返します

$result->row1つ以上が連想配列として返される場合は、最初の行のデータが含まれます

$result->rowsforeachを使用してループオーバーするのに理想的な行結果の配列が含まれています

$result->num_rows返された結果の数が含まれます

$this->dbオブジェクトが持っているいくつかの追加のメソッドもあります

$this->db->escape()渡された値にmysql_real_escape_string()を使用します

$this->db->countAffectedUPDATEクエリの影響を受ける行数などを返します

$this->db->getLastId()mysql_insert_id()を使用して最後の自動増分IDを返します


予約変数を理解する

OpenCartには、標準の、、、、、、およびの代わりに使用する事前定義された変数$_GETがあります$_POST$_SESSION$_COOKIE$_FILES$_REQUEST$_SERVER

$_SESSION$this->session->dataデータが連想配列である場合を使用して編集されます$_SESSION

他のすべては、を使用してアクセスでき$this->request、有効化/無効化された魔法の引用符に準拠するように「クリーンアップ」されています。

$_GETになります$this->request->get

$_POSTになります$this->request->post

$_COOKIEになります$this->request->cookie

$_FILESになります$this->request->files

$_REQUESTになります$this->request->request

$_SERVERになります$this->request->server


概要

上記は開発者向けの防弾ガイドではありませんが、初心者にとって良い出発点となることを願っています。

于 2012-11-21T01:11:26.860 に答える
37

グローバルライブラリメソッド:基本的なopencartライブラリ関数とその機能。これらのほとんどは、カタログまたは管理フォルダー(コントローラー、モデル、ビュー)のどこからでも呼び出すことができます。

CACHE
$this->cache->delete($key) - Deletes cache [product, category, country, zone, language, currency,
manufacturer]

CART
$this->cart->getProducts() Gets all products currently in the cart including options, discounted prices, etc.
$this->cart->add( $product_id, $qty = 1, $options = array()) - Allows you to add a product to the cart
$this->cart->remove( $key ) - Allows you to remove a product from the cart
$this->cart->clear() - Allows you to remove all products from the cart
$this->cart->getWeight() - Sum of the weight of all products in the cart that have require shipping set to Yes
$this->cart->getSubTotal() - returns the subtotal of all products added together before tax
$this->cart->getTotal() - returns the total of all products added together after tax
$this->cart->countProducts() - returns the count of all product in the cart
$this->cart->hasProducts() - returns true if there is at least one item in the cart
$this->cart->hasStock() - returns false if there is at least one item in the cart that is out of stock
$this->cart->hasShipping() - returns true if there is at least one item in the cart that requires shipping
$this->cart->hasDownload() - returns true if there is at least one item in the cart that has a download
associated

CONFIG
$this->config->get($key) - returns setting value by keyname based on application (catalog or admin)
$this->config->set($key, $value) - set the value to override the setting value. DOES NOT SAVE TO DATABASE

CURRENCY
$this->currency->set($currency) - set or override the currency code to be used in the session
$this->currency->format($number, $currency = '', $value = '', $format = TRUE) - format the currency
$this->currency->convert($value, $from, $to) - convert a value from one currency to another. Currencies must
exist
$this->currency->getId() - get the database entry id for the current currency (1, 2, 3, 4)
$this->currency->getCode() - get the 3-letter iso code for the current currency (USD, EUR, GBP, AUD, etc)
$this->currency->getValue($currency) - get the current exchange rate from the database for the specified
currency.
$this->currency->has(currency) - Check if a currency exists in the opencart currency list

CUSTOMER
$this->customer->login($email, $password) - Log a customer in
$this->customer->logout() - Log a customer out
$this->customer->isLogged() - check if customer is logged in
$this->customer->getId() - get the database entry id for the current customer (integer)
$this->customer->getFirstName() - get customer first name
$this->customer->getLastName() - get customer last name
$this->customer->getEmail() - get customer email
$this->customer->getTelephone() - get customer telephone number
$this->customer->getFax() - get customer fax number
$this->customer->getNewsletter() - get customer newsletter status
$this->customer->getCustomerGroupId() - get customer group id
$this->customer->getAddressId() - get customer default address id (maps to the address database field)

DATABASE
$this->db->query($sql) - Execute the specified sql statement. Returns row data and rowcount.
$this->db->escape($value) - Escape/clean data before entering it into database
$this->db->countAffected($sql) - Returns count of affected rows from most recent query execution
$this->db->getLastId($sql) - Returns last auto-increment id from more recent query execution 4

DOCUMENT (*Called from controller only before renderer)
$this->document->setTitle($title) - Set page title
$this->document->getTitle()- Get page title
$this->document->setDescription($description) - Set meta description
$this->document->getDescription()- Get meta description
$this->document->setKeywords()- Set meta keywords
$this->document->getKeywords()- Get meta keywords
$this->document->setBase($base) - Set page base
$this->document->getBase() - Get page base
$this->document->setCharset($charset) - Set page charset
$this->document->getCharset() - Get page charset
$this->document->setLanguage($language) - Set page language
$this->document->getLanguage()- Get page language
$this->document->setDirection($direction) - Set page direction (rtl/ltr)
$this->document->getDirection()- Get page direction (rtl/ltr)
$this->document->addLink( $href, $rel ) – Add dynamic <link> tag
$this->document->getLinks()- Get page link tags
$this->document->addStyle( $href, $rel = 'stylesheet', $media = 'screen' ) – Add dynamic style
$this->document->getStyles()- Get page styles
$this->document->addScript( $script ) - Add dynamic script
$this->document->getScripts()- Get page scripts
$this->document->addBreadcrumb($text, $href, $separator = ' &gt; ') – Add breadcrumb
$this->document->getBreadcrumbs()- Get Breadcrumbs

ENCRYPT
$this->encryption->encrypt($value) - Encrypt data based on key in admin settings
$this->encryption->decrypt($value) - Decrypt data based on key in admin settings

IMAGE
$this->image->resize($width = 0, $height = 0)

JSON
$this->json->encode( $data )
$this->json->decode( $data , $assoc = FALSE)

LANGUAGE
$this->language->load($filename);

LENGTH
$this->length->convert($value, $from, $to) - convert a length to another. units must exist
$this->length->format($value, $unit, $decimal_point = '.', $thousand_point = ',') - format the length to use
unit

LOG
$this->log->write($message) - Writes to the system error log

REQUEST
$this->request->clean($data) - Cleans the data coming in to prevent XSS
$this->request->get['x'] - Same as $_GET['x']
$this->request->post['x'] - Same as $_POST['x']

RESPONSE
$this->response->addHeader($header) - additional php header tags can be defined here
$this->response->redirect($url) - redirects to the url specified

TAX
$this->tax->setZone($country_id, $zone_id) - Set the country and zone id for taxing (integer)
$this->tax->calculate($value, $tax_class_id, $calculate = TRUE) - Calculate all taxes to be added to the total
$this->tax->getRate($tax_class_id) - Get the rates of a tax class id
$this->tax->getDescription($tax_class_id) - Get the description of a tax class id
$this->tax->has($tax_class_id) - Check if a tax class id exists in opencart

SESSION
$this->session->data['x'] - Same as $_SESSION['x']  
于 2013-10-10T09:33:29.127 に答える
10

初心者の開発者向けのドキュメントが掲載されたOpenCartWikiWebサイトがあります。詳細については、以下のURLに従ってください。

http://wiki.opencarthelp.com/doku.php?id=start
http://wiki.opencarthelp.com/doku.php?id=methods_reference

インターネットアーカイブリンク

http://web.archive.org/web/20160305131349/http://wiki.opencarthelp.com/doku.php?id=start http://web.archive.org/web/20160305131349/http://wiki .opencarthelp.com / doku.php?id = methods_reference

たとえば、メソッドリファレンスには次の詳細があります。

  1. お客様ログイン
  2. DBアクセス
  3. ショッピングカートの取り扱い
  4. 構成
  5. キャッシュ
  6. 通貨の取り扱い

まだ作成中のページがいくつかありますが、それは役立つでしょう。

[アップデート]

2018年1月の時点で、opencarhelp.comドメインはダウンしています。

于 2014-05-30T05:56:33.767 に答える
6

このトピックはすでに何度も回答されていますが、私の経験に基づいて、OpenCartを習得するための別のアプローチを提供したいと思います。

実践的学習

少数のファイルを使用して独自のOpenCartフレームワークを最初から作成することにより、すべてがどのようにまとめられているかを理解できます。OpenCartのファイル構造を模倣します。

ファイルを作成するindex.php

<?php
// My simpleCart

1.レジストリ

Opencartは、レジストリパターンを使用して、ロードされたクラスのすべてのインスタンスを一覧表示します。これは、OpenCartアプリの心臓部です。次に、レジストリオブジェクトは、他のオブジェクトにすばやくアクセスできるように、すべてのカテゴリ、モデル、およびライブラリに渡されます。

パスを使用してファイルを作成する/system/engine/registry.php

<?php
// Registry class. 
class Registry
{
    private $data = array();

    public function set($key, $value){
        $this->data[$key] = $value;
    }

    public function get($key){
        return (isset($this->data[$key])) ? $this->data[$key] : false;
    }
}

あなたの中でindex.php

<?php
// My simpleCart

//load dependency files
require_once('system/engine/registry.php');

//initialize registry
$registry = new Registry;

2.出力

次に、将来HTMLになる出力を追加しましょう。結局のところ、全体的なアイデアは、ブラウザにテキストの文字列を送信することです。

ファイルを作成するsystem/library/response.php

<?php
class Response {
    private $output;

    public function getOutput() {
        return $this->output;
    }

    public function setOutput($output) {
        $this->output = $output;
    }

    public function output() {
        if ($this->output) {
            echo $this->output;
        }
    }
}

そしてあなたの中でindex.php

<?php
// My simpleCart

//load dependency files
require_once('system/engine/registry.php');
require_once('system/library/response.php');

//initialize registry
$registry = new Registry;

//initialize response
$response = new Response;
//add response object to the registry
$registry->set('response', $response);

//lets set an output as a test
$registry->get('response')->setOutput('Hello World');

//send the output to the client
$registry->get('response')->output();

例としてのみHelloworldを追加したことに注意してください。後で削除します。サイトを更新して確認してください。ブラウザにが表示されますHello World

3.コントローラー

コントローラをページと考えてください。クライアントに表示される内容(テキスト、html、json、ダウンロード、さらには画像)を定義します。今のところ、テキストを送信するページが必要です。

ページのコントローラーを作成しhomeます。

パスを含むファイルを追加するcatalog/controller/common/home.php

<?php

class ControllerCommonHome{

    private $registry = array();

    public function __construct($registry){
        $this->registry = $registry;
    }

    public function index(){

        $output = 'Home Page';
        //using the registry to get the response object and set the Output
        $this->registry->get('response')->setOutput($output);
    }
}

と編集しますindex.php

<?php
// My simpleCart

//load registry
require_once('system/engine/registry.php');
//load response
require_once('system/library/response.php');

//initialize registry
$registry = new Registry;

//initialize response
$response = new Response;
//add resoinse object to the registry
$registry->set('response', $response);

//load controller common/home
require_once('catalog/controller/common/home.php');
$controller = new ControllerCommonHome($registry);
$controller->index();

//send the output to the client
$registry->get('response')->output();

$refistryコントローラ内でアクセスできるように、をControllerCommonHomeに渡した方法に注目してください。

4.ルーター

コントローラーをハードコーディングする必要はありません。routeURLアドレスのパラメーターを使用して、ロードするコントローラーをカートに指示します。

パスを使用してファイルを作成するsystem/library/request.php

<?php
class Request {
    public $get = array();

    //for now I just need the $_GET parameter
    public function __construct() {
        $this->get = $_GET;
    }
}

ルートに基づいてControllerファイルの初期化を担当するRouterクラスを作成します(つまり、動的にコントローラーを呼び出します)

<?php
class Router {
    private $registry;

    public function __construct($registry) {
        $this->registry = $registry;
    }

    public function dispatch($route) {
        require_once('catalog/controller/'.$route.'.php');
        $class = "Controller".str_replace('/', '', $route);
        $controller = new $class($this->registry);
        $controller->index();
    }
}

あなたにそれをロードしますindex.php

<?php
require_once('system/engine/registry.php');
require_once('system/engine/router.php');
require_once('system/library/response.php');
require_once('system/library/request.php');

$registry = new Registry;

$response = new Response;
$registry->set('response', $response);

$request = new Request;
$registry->set('request', $request);

//get the route from the url
if(isset($registry->get('request')->get['route'])){
    $route = $registry->get('request')->get['route'];
}else{
    $route = 'common/home';
}

//initiate the router and dispatch it base on the route
$router = new Router($registry);
$router->dispatch($route);


$registry->get('response')->output();

すべてをにロードして$registryからに渡し、次にそれをに渡す方法に注目$routerして$controllerください。

この投稿はすでに長すぎますが、OpenCartのMVCパターンの基本的な理解が得られることを願っています。

この投稿を続けて、モデルやビューなどの他のものがどのように機能するかを教えてほしい場合は、この回答を評価してください。

また、私のYoutubehttps ://www.youtube.com/dreamventionと私のブログhttps://dreamvention.com/blogもチェックしてください。皆さんのためにさらにヒントやチュートリアルを投稿します。

于 2019-03-06T06:15:12.720 に答える
1

PHPは、 5000を超える組み込み関数を備えたかなり大きな言語であるため、新しいプラットフォームを学習するための1つの戦略は、PHPが最も頻繁に使用する関数を特定し、それらをよく理解するために時間を費やすことです。

OpenCartソースコードでいくつかのクエリを実行しました。最も一般的に使用される関数のトップ10は次のとおりです。

array()
count()
explode()
implode()
mktime()
delete()
time()
date()
sprintf()
list()

ここにリストされている52個すべてと、一般的に使用される関数を識別するために任意のコードベースで使用できるLinux bashコマンド: https ://www.antropy.co.uk/blog/efficient-learning-for-new-opencart-developers/

于 2017-11-20T10:18:42.603 に答える
0

このYouTube動画の再生リストは、OpenCart開発者のGurusになるのにも役立ちます。

OpenCartビデオチュートリアル

  1. 紹介と目次このビデオでは、シリーズの紹介を紹介しています。
  2. OpenCartインストールローカルホストこのビデオでは、ローカルホストでのOpenCartインストールについて説明します。
  3. Opencartのファイルとフォルダの構造OpenCartのファイルとフォルダの構造について説明します
  4. OpenCartでのデータベーステーブルスキーマの作成データベーステーブルスキーマと、OpenCartでデータベーステーブルを作成する方法を示します。
  5. OpenCartライブラリの事前定義されたオブジェクトのメソッドOpenCartライブラリの事前定義されたオブジェクトのメソッドについて説明し、それらの場所を示します。
  6. OpenCartでのMVCLパターン、コードフロー、および要求と応答OpenCartでのMVCLパターン、コードフロー、および要求と応答を示します。次の図のようにフローを説明します。 コードで記述されたMVCL

  7. Opencartモジュールのインストール、構成、およびアンインストールモジュールをアップロードしてから、OpenCart 3モジュール/拡張機能をインストール、構成、およびアンインストールする3つの方法を示します。

  8. Opencart3のレイアウトと位置OpenCart3のレイアウトと位置について説明します。カテゴリページの例を示して、さまざまなページのカスタマイズレイアウトを表示する方法を示します。カテゴリごとに異なるレイアウトを示します。

  9. Opencartのイベントの概要OpenCartのイベントとは何か、それらがどのように機能するのか、そして何がそれらをとても便利にするのかを学びます。

  10. 開発者向けのOpencartAPIドキュメントこのビデオでは、カスタムOpencartAPIの使用方法と作成方法を紹介します。

これらのビデオを見ると、コーディングを開始できます:)

于 2019-01-06T19:44:29.497 に答える