ओपनकार्ट गुरु कैसे बनें? [बन्द है]


98

ऐसा लगता है कि उनके पास अपने आधिकारिक मंचों पर कुछ एपीआई कॉल के अलावा कोई दस्तावेज नहीं है। मेरे पास Zend फ्रेमवर्क और CodeIgniter फ्रेमवर्क के साथ अनुभव है। क्या कोई ओपनकार्ट स्वामी मुझे इसे सीखने का सबसे अच्छा तरीका सुझा सकता है और कम से कम समय में मास्टर कर सकता है? मुझे जल्द ही इसके साथ एक बड़ा प्रोजेक्ट करना है।


देखें docs.opencart.com , और Qphoria द्वारा ढांचे सिंहावलोकन । इसके अलावा OpenCart फ़ोरम> सहायता पर थ्रेड्स के माध्यम से ब्राउज़ करें । भविष्य में, उम्मीद है कि हमारे पास area51.stackexchange.com/proposals/77558/opencart
Pacerier

यह वास्तव में एक महत्वपूर्ण सवाल है, कभी-कभी एसओ मानकों पर काबू पाना वास्तव में मददगार होता है ...
KAD

1
इस सवाल के लिए बहुत बहुत धन्यवाद, इसने मुझे बहुत मदद की
बिपुल रॉय

@BipulRoy मुझे खुशी है! लगता है जैसे यह अब एक लोकप्रिय सवाल है!
कोडक्रैक

जवाबों:


311

OpenCart 1.5.X डेवलपर शुरुआती के लिए त्वरित आरंभ गाइड

यह गाइड PHP, OOP और MVC आर्किटेक्चर से पहले से परिचित डेवलपर्स के लिए लिखा गया है

निम्नलिखित में, आप कार्ट के कैटलॉग पक्ष के लिए उदाहरण देखेंगे। व्यवस्थापन पक्ष संबंधित अनुभाग में नोट किए गए विचारों के अपवाद के साथ कार्य में समान है


पुस्तकालयों को समझना

पुस्तकालय कार्यक्षमता के सभी नियंत्रक, मॉडल और उपयोग के माध्यम से सुलभ है $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/bbbजिसे दो भागों के रूप में देखा जाना चाहिए, हालांकि कुछ में तीन भाग होते हैं aaa/bbb/cccपहला भाग aaaआमतौर पर एक सामान्य फ़ोल्डर जैसे नियंत्रक या टेम्पलेट फ़ोल्डर के भीतर फ़ोल्डर से संबंधित होता है। दूसरा भाग आम तौर पर प्रासंगिक .phpया .tplविस्तार के बिना, फ़ाइल नाम से संबंधित है । तीसरे भाग को नीचे दिए गए "अंडरस्टैंडिंग कंट्रोलर्स" सेक्शन में समझाया गया है


भाषाओं को समझना

भाषाओं को सबफ़ोल्डर में /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का उपयोग किया जाता है।

नियंत्रक फ़ाइल को खोलने पर, आप एक पास्कल केस क्लासनाम देखेंगे जो क्लास को बढ़ा रहा है Controller, जिसे कहा जाता है ControllerProductSearch। यह फिर से रूट के लिए विशिष्ट है, Controllerइसके बाद सबफ़ोल्डर नाम और फ़ाइल नाम के बिना विस्तार किए गए कैपिटल। पूंजीकरण वास्तव में आवश्यक नहीं है, लेकिन यह आसान पठनीयता के लिए अनुशंसित है। यह ध्यान देने योग्य है कि वर्ग नाम अक्षरों और संख्याओं के अलावा सबफ़ोल्डर और फ़ाइल नाम से कोई मान नहीं लेते हैं। अंडरस्कोर हटा दिए जाते हैं।

कक्षा के भीतर विधियां हैं। घोषित वर्ग में विधियाँ publicमार्ग से चलाने के लिए सुलभ privateहैं - नहीं हैं। डिफ़ॉल्ट रूप से, मानक दो भाग मार्ग ( aaa/bbbऊपर) के साथ, एक डिफ़ॉल्ट index()विधि कहा जाता है। यदि किसी मार्ग ( cccऊपर) के तीसरे भाग का उपयोग किया जाता है, तो इस विधि को इसके बजाय चलाया जाएगा। उदाहरण के लिए, फ़ाइल और कक्षा account/return/insertको लोड करेगा /catalog/controller/account/return.php, और insertविधि को कॉल करने का प्रयास करेगा


मॉडल को समझना

ओपनकार्ट में मॉडल /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;

यदि आप एक्स्ट्रेक्ट () विधि से परिचित होते हैं जो प्रत्येक कुंजी को एक चर में परिवर्तित करता है, तो इसे समझना आसान है । तो example_varकुंजी बन जाती है $example_varऔर दृश्य में इस तरह से पहुँचा जा सकता है।


विषयों को समझना

थीम केवल कैटलॉग पक्ष के लिए उपलब्ध हैं, और मूल रूप से टेम्पलेट, स्टाइलशीट और थीम छवियों का एक फ़ोल्डर है। थीम फ़ोल्डर को /catalog/view/theme/थीम नाम के बाद फ़ोल्डर में रखा जाता है । फ़ोल्डर नाम के अपवाद के साथ महत्व का नहीं है defaultफ़ोल्डर

व्यवस्थापक पक्ष का उपयोग करता है /admin/view/template/( /theme/theme-name/रास्ते से लंघन करना क्योंकि यह अलग-अलग विषयों की अनुमति नहीं देता है)

टेम्पलेट फ़ाइलें templateथीम फ़ोल्डर के भीतर एक फ़ोल्डर में रहती हैं । क्या वर्तमान में चयनित थीम के लिए कोई भी टेम्पलेट उपलब्ध नहीं होना चाहिए, डिफ़ॉल्ट फ़ोल्डर के टेम्पलेट का उपयोग फ़ॉलबैक के रूप में किया जाता है। इसका मतलब है कि थीम बहुत कम फ़ाइलों के साथ बनाई जा सकती हैं और अभी भी पूरी तरह से काम कर सकती हैं। यह कोड के दोहराव को भी कम करता है और उन्नयन के रूप में मुद्दे बनाए जाते हैं


विचारों को समझना (टेम्प्लेट)

भाषा और मॉडल के साथ, दृश्य फ़ाइल आमतौर पर मार्ग से संबंधित होती है, हालांकि यह बिल्कुल भी नहीं है। कैटलॉग साइड में टेम्प्लेट आमतौर पर /catalog/view/theme/your-theme/template/तब तक पाए जाते हैं जब तक कि यह मौजूद न हो, इस मामले में डिफ़ॉल्ट थीम के टेम्प्लेट का उपयोग किया जाएगा। ऊपर हमारे खोज पृष्ठ उदाहरण के लिए, फ़ाइल है product/search.tpl। तीन भागों वाले मार्गों के लिए, यह आम तौर पर होता है, 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->row यदि एक या अधिक को एक साहचर्य सरणी के रूप में लौटाया जाता है तो पहली पंक्ति का डेटा होता है

$result->rows पंक्ति परिणामों की एक सरणी होती है, जिसमें फ़ॉर्च का उपयोग करके लूपिंग के लिए आदर्श होता है

$result->num_rows इसमें दिए गए परिणामों की संख्या शामिल है

$this->dbऑब्जेक्ट में कुछ अतिरिक्त विधियाँ भी हैं

$this->db->escape()पास किए गए मूल्य पर mysql_real_escape_string () का उपयोग करता है

$this->db->countAffectedUPDATEक्वेरी वगैरह से प्रभावित पंक्तियों की संख्या लौटाता है

$this->db->getLastId()mysql_insert_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


सारांश

हालांकि ऊपर डेवलपर्स के लिए बुलेटप्रूफ गाइड नहीं है, उम्मीद है कि यह शुरू होने वाले लोगों के लिए एक अच्छा शुरुआती बिंदु होगा


3
धन्यवाद! आपको यह कहाँ पर मिला?
कोडक्रैक

64
मैने यह लिखा। मुझे लगा कि इसे लिखने की जरूरत है और यह खोज फिट है
जेई गिलफोर्ड 1

2
बहुत अच्छा। अधिकांश गाइडों की तुलना में अधिक जानकारीपूर्ण तरीका। क्या आपके पास किसी भी अवसर पर एक उन्नत है?
कोडक्रैक

3
इसे सामुदायिक विकी का दर्जा दिया जाना चाहिए
Stann0rz

1
@UltimateKing - यह गाइड आपको पहले से ही पर्याप्त जानकारी प्रदान करता है ताकि आप अपने स्वयं के मॉड बनाने के साथ शुरू कर सकें। नेट पर मॉड्यूल विकास के लिए विशिष्ट ट्यूटोरियल भी हैं
जे गिलफोर्ड में

36

ग्लोबल लाइब्रेरी मेथड्स: बेसिक ओपेनकार्ट लाइब्रेरी फंक्शन्स के साथ-साथ उनकी फंक्शन्स के लिए, इनमें से ज्यादातर को कैटलॉग या एडमिन फोल्डर (कंट्रोलर, मॉडल, व्यू) में कहीं से भी बुलाया जा सकता है।

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']  

9

शुरुआत डेवलपर्स के लिए प्रलेखन के साथ एक OpenCart Wiki वेबसाइट है। अधिक विवरण के लिए नीचे दिए गए यूआरएल का पालन करें:

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 तक, opencarhelp.com डोमेन नीचे है।


अभी भी कुछ महीनों के बाद बहुत अधिक जानकारी गायब हो रही है। क्या इस परियोजना को छोड़ दिया गया है?
पचेरियर

@ स्पेसर, मुझे उस पर यकीन नहीं है।
Dharmang

यह एक बेहतरीन पेज है, यहां तक ​​कि ओपन कार्ट विकी रेफरेंस भी है। आप यहां लिंक देख सकते हैं wiki.opencarthelp.com/doku.php?id=opencart_framework
नासिम

4

हालाँकि इस विषय पर पहले ही कई बार जवाब दिया जा चुका है, मैं अपने अनुभव के आधार पर ओपनकार्ट में महारत हासिल करने के लिए एक और दृष्टिकोण प्रदान करना चाहूंगा।

करके सीखना

मुट्ठी भर फाइलों के साथ खरोंच से अपना खुद का ओपनकार्ट ढांचा बनाकर आप समझ सकते हैं कि सब कुछ एक साथ कैसे रखा जाता है। मैं आपके लिए 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();

सूचना मैंने हैलो दुनिया को केवल एक उदाहरण के रूप में जोड़ा। हम इसे आगे हटा देंगे। इसे जांचने के लिए अपनी साइट को रिफ्रेश करें। ब्राउज़र को प्रदर्शित करना चाहिए 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कंट्रोलर कोमोनहोम को पास किया ताकि मैं इसे कंट्रोलर के अंदर एक्सेस कर सकूं।

4. राउटर

हम नहीं चाहते कि नियंत्रक हार्डकोड हो, ठीक है। हम routeअपनी गाड़ी को यह बताने के लिए url पते के एक पैरामीटर का उपयोग करेंगे कि कौन सा नियंत्रक लोड करना है।

पथ के साथ एक फ़ाइल बनाएँ system/library/request.php

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

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

राउटर वर्ग बनाएं जो मार्ग के आधार पर नियंत्रक फ़ाइल को प्रारंभ करने के लिए जिम्मेदार होगा (दूसरे शब्दों में: गतिशील रूप से नियंत्रक को कॉल करें)

<?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 पैटर्न की एक बुनियादी समझ देगा।

यदि आप चाहते हैं कि मैं इस पोस्ट को जारी रखूं और आपको बताऊं कि मॉडल और विचारों की तरह अन्य चीजें कैसे काम करती हैं, तो इस उत्तर को रेट करें ताकि मुझे पता चले।

इसके अलावा मेरे Youtube https://www.youtube.com/dreamvention और मेरे ब्लॉग की जांच करें https://dreamvention.com/blog मैं आप लोगों के लिए और भी टिप्स और ट्यूटोरियल पोस्ट करूंगा!


1

5000 से अधिक अंतर्निहित कार्यों के साथ PHP एक काफी बड़ी भाषा है, इसलिए एक नया मंच सीखने के लिए एक रणनीति यह पहचानना है कि कौन से फ़ंक्शन यह सबसे अधिक बार उपयोग करता है और उन लोगों को अच्छी तरह से जानने के लिए कुछ समय व्यतीत करता है।

मैंने OpenCart स्रोत कोड पर कुछ प्रश्न चलाए हैं और शीर्ष 10 सबसे अधिक उपयोग किए जाने वाले कार्य हैं:

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

सभी 52 यहां और साथ ही लिनक्स बैश कमांड सूचीबद्ध हैं जिन्हें आप आमतौर पर उपयोग किए जाने वाले कार्यों की पहचान करने के लिए किसी भी कोडबेस पर उपयोग कर सकते हैं: https://www.antropy.co.uk/blog/efficient-learning-for-new-opencart-developers/


1

यह YouTube वीडियो प्लेलिस्ट भी OpenCart डेवलपर गुरु बनने में मददगार हो सकती है:

OpenCart वीडियो ट्यूटोरियल

  1. परिचय और सामग्री की तालिका यह वीडियो श्रृंखला की शुरूआत के माध्यम से जाता है
  2. ओपनचार्ट इंस्टॉलेशन लोकलहोस्ट यह वीडियो लोकलहोस्ट में ओपनकार्ट इंस्टॉलेशन से होकर गुजरता है
  3. Opencart की फ़ाइलें और फ़ोल्डर संरचना यह OpenCart की फ़ाइलों और फ़ोल्डरों की संरचना का वर्णन करती है
  4. OpenCart में डेटाबेस टेबल स्कीमा बनाना यह डेटाबेस टेबल स्कीमा दिखाता है और दिखाता है कि OpenCart में डेटाबेस टेबल कैसे बनाया जाता है
  5. OpenCart लाइब्रेरी पूर्वनिर्धारित ऑब्जेक्ट्स की विधियाँ यह OpenCart लाइब्रेरी पूर्वनिर्धारित ऑब्जेक्ट्स के तरीकों का वर्णन करता है और दिखाता है कि उन्हें कहाँ खोजना है।
  6. OpenCart में MVCL पैटर्न, कोड प्रवाह और अनुरोध और प्रतिक्रिया यह MVCL पैटर्न, कोड प्रवाह और OpenCart में अनुरोध और प्रतिक्रिया दिखाता है। वे नीचे दिए गए चित्र के अनुसार प्रवाह का वर्णन करते हैं: MVCL कोड के साथ वर्णित है

  7. Opencart मॉड्यूल को स्थापित, कॉन्फ़िगर और अनइंस्टॉल करें यह मॉड्यूल अपलोड करने के तीन तरीके दिखाता है, फिर OpenCart 3 मॉड्यूल या एक्सटेंशन को स्थापित, कॉन्फ़िगर और अनइंस्टॉल करें।

  8. Opencart 3 में लेआउट और स्थिति यह OpenCart 3 लेआउट और स्थिति का वर्णन करता है। यह दिखाता है कि विभिन्न पृष्ठों के लिए अनुकूलित लेआउट कैसे दिखाएं, श्रेणियों के पृष्ठों का उदाहरण देते हुए। हम एक अलग श्रेणी के लिए अलग-अलग लेआउट दिखाते हैं।

  9. Opencart का इवेंट अवलोकन आप सीखेंगे कि OpenCart में क्या ईवेंट हैं, वे कैसे काम करते हैं और उन्हें क्या उपयोगी बनाते हैं।

  10. डेवलपर के लिए Opencart API डॉक्यूमेंटेशन यह वीडियो दिखाएगा कि कस्टम ऑपनकार्ट API का उपयोग कैसे करें और कैसे करें

एक बार जब आप ये वीडियो देख लेंगे तो आप कोडिंग शुरू कर सकते हैं :)

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.