복붙노트

OpenCart 전문가가되는 방법?

PHP

OpenCart 전문가가되는 방법?

공식 포럼에서 일부 API 호출을 제외하고는 문서가없는 것처럼 보입니다. Zend 프레임 워크와 CodeIgniter 프레임 워크에 대한 경험이 있습니다. 어떤 OpenCart 마스터가 나에게 그것을 배우고 가장 짧은 시간에 마스터하는 가장 좋은 방법을 추천 할 수 있습니까? 나는 큰 프로젝트를 곧해야한다.

해결법

  1. ==============================

    1.이 가이드는 이미 PHP, OOP 및 MVC 아키텍처에 익숙한 개발자를 위해 작성되었습니다.

    이 가이드는 이미 PHP, OOP 및 MVC 아키텍처에 익숙한 개발자를 위해 작성되었습니다.

    다음에서는 장바구니의 카탈로그 측면에 대한 예제를 볼 수 있습니다. 관리 측면은 기능면에서 관련 섹션에 명시된보기를 제외하고는 동일합니다

    모든 라이브러리 기능은 $ this-> library_name을 사용하여 컨트롤러, 모델 및 뷰를 통해 액세스 할 수 있습니다. 이들 모두는 / system / library / 폴더에서 찾을 수 있습니다. 예를 들어 현재 장바구니 제품에 액세스하려면 /system/library/cart.php에있는 Cart 클래스를 사용해야하며 $ this-> cart-> getProducts ()를 사용하여 액세스 할 수 있습니다.

    일반적으로 사용되는 항목

    OpenCart의 프레임 워크는 쿼리 문자열 매개 변수에서 route = aaa / bbb / ccc를 사용하여로드 할 항목을 파악하고 각 페이지에 대해 편집해야하는 파일을 찾는 기반 기능입니다. 대부분의 경로는 실제로 두 부분으로 표시되어야하는 aaa / bbb 만 사용하지만 일부는 세 부분으로 구성됩니다. aaa / bbb / ccc 첫 번째 부분은 일반적으로 제어기 또는 템플리트 폴더와 같은 일반 폴더 내의 폴더와 관련이 있습니다. 두 번째 부분은 일반적으로 관련 .php 또는 .tpl 확장자가없는 파일 이름과 관련이 있습니다. 세 번째 부분은 아래의 "컨트롤러 이해"섹션에서 설명합니다.

    언어는 / catalog / language / 폴더의 your-language 하위 폴더에 저장됩니다. 이 부분에서 여러 페이지에 걸쳐 사용되는 일반적인 텍스트 값은 폴더 내의 your-language.php 파일에 저장되므로 카탈로그 측면의 영어에 대해서는 catalog / language / english / english.php의 값을 찾을 수 있습니다 . 특정 페이지 텍스트의 경우 페이지의 경로가 필요합니다. 일반적으로 원하는 언어 파일을 지정할 수있는 것은 아닙니다. 예를 들어 검색 페이지에는 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 메소드없이 자동으로로드되고 사용할 수 있습니다

    컨트롤러는 경로를 기반으로로드되며 이해하기 쉽습니다. 컨트롤러는 / catalog / controller / 폴더에 있습니다. 마지막 예에서 계속해서 검색 페이지의 컨트롤러는이 폴더 내의 /product/search.php에 있습니다. .php 다음에 경로가 사용된다는 것을 다시 한번 확인하십시오.

    컨트롤러 파일을 열면 ControllerProductSearch라는 Controller 클래스를 확장하는 Pascal Case 클래스 이름이 표시됩니다. 이것은 다시 경로와 관련이 있습니다. Controller와 함께 확장명없이 대문자 이름과 파일 이름을 대문자로 표시합니다. 대문자 사용은 실제로 요구되지 않지만 가독성을 위해 권장됩니다. 클래스 이름이 글자와 숫자가 아닌 하위 폴더와 파일 이름에서 값을 가져 오지 않는다는 점은 주목할 가치가 있습니다. 밑줄이 제거됩니다.

    클래스 내에는 메소드가 있습니다. public으로 선언 된 클래스의 메서드는 경로를 통해 실행할 수 있습니다. private은 그렇지 않습니다. 기본적으로 표준 두 부분 경로 (위의 aaa / bbb)를 사용하면 기본 index () 메서드가 호출됩니다. 경로의 세 번째 부분 (위의 ccc)이 사용되면이 메소드가 대신 실행됩니다. 예를 들어 account / return / insert는 /catalog/controller/account/return.php 파일과 클래스를로드하고 insert 메소드를 호출합니다.

    OpenCart의 모델은 / catalog / model / 폴더에 있으며 경로가 아닌 기능을 기준으로 그룹화되어 있으므로 컨트롤러를 통해로드해야합니다.

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

    그러면 yyy.php라는 하위 폴더 xxx에 파일이로드됩니다. 그런 다음 객체를 통해 사용할 수 있습니다.

    $this->model_xxx_yyy
    

    컨트롤러와 마찬가지로 public 메서드 만 호출 할 수 있습니다. 예를 들어 이미지 크기를 조정하려면 도구 / 이미지 모델을 사용하고 다음과 같이 resize 메서드를 호출합니다.

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

    컨트롤러에서 뷰에 값을 전달하려면 데이터를 $ this-> data 변수에 할당하면됩니다.이 변수는 본질적으로 key => value 쌍의 배열입니다. 예로서

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

    각 키를 변수로 변환하는 extract () 메서드에 익숙하다면이 뷰에 액세스하는 것이 조금 이해하기 쉬울 것입니다. 따라서 example_var 키는 $ example_var가되고 뷰에서 이와 같이 액세스 할 수 있습니다.

    테마는 카탈로그 측면에서만 사용할 수 있으며 기본적으로 템플릿, 스타일 시트 및 테마 이미지의 폴더입니다. 테마 폴더는 / catalog / view / theme / 폴더에 놓이고 그 뒤에 테마 이름이옵니다. 폴더 이름은 기본 폴더를 제외하고는 중요하지 않습니다.

    관리자 측은 / admin / view / template /을 사용합니다 (다른 테마를 허용하지 않으므로 / theme / theme-name /을 경로에서 제외합니다)

    템플릿 파일은 테마 폴더 내의 템플릿 폴더에 있습니다. 현재 선택한 테마에 사용할 수없는 템플릿이 있으면 기본 폴더의 템플릿이 대신 대체 파일로 사용됩니다. 즉, 테마가 매우 적은 파일로 생성 될 수 있고 완전히 기능을 수행 할 수 있습니다. 또한 업그레이드가되면 코드 중복 및 문제가 줄어 듭니다.

    언어 및 모델과 마찬가지로보기 파일은 일반적으로 경로와 관련이 있지만 반드시 그럴 필요는 없습니다. 카탈로그 측면의 템플리트는 / 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 제안하는 경우 데이터베이스 접두사가있는 경우이를 포함하는 상수입니다

    $ result는 SELECT 쿼리에 대해 몇 가지 속성을 포함하는 객체를 반환합니다.

    $ result-> row는 하나 이상의 연관 배열로 반환되는 경우 첫 번째 행의 데이터를 포함합니다.

    $ result-> rows는 행 결과 배열을 포함하고 있으므로 foreach를 사용하여 반복 할 때 이상적입니다.

    $ result-> num_rows는 반환 된 결과의 개수를 포함합니다.

    $ this-> db 객체가 가지고있는 몇 가지 추가 메소드가 있습니다.

    $ this-> db-> escape ()는 전달 된 값에 mysql_real_escape_string ()을 사용합니다.

    $ this-> db-> countAffected는 UPDATE 쿼리의 영향을받는 행 수를 반환합니다.

    $ this-> db-> getLastId ()는 mysql_insert_id ()를 사용하여 마지막 자동 증가 ID를 반환한다.

    OpenCart에는 표준 $ _GET, $ _POST, $ _SESSION, $ _COOKIE, $ _FILES, $ _REQUEST 및 $ _SERVER 대신 사용할 사전 정의 된 변수가 있습니다.

    $ _SESSION은 $ this-> session-> data를 사용하여 편집됩니다. 여기서 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가됩니다.

    위의 내용은 개발자를위한 강력한 가이드가 아니지만 시작하기 전에 개발자에게 좋은 출발점이 될 것입니다.

  2. ==============================

    2.전역 라이브러리 메소드 : 기본 opencart 라이브러리 함수와 함께 기능, 대부분은 카탈로그 또는 관리 폴더 (컨트롤러, 모델, 뷰)의 어디에서나 호출 할 수 있습니다.

    전역 라이브러리 메소드 : 기본 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']  
    
  3. ==============================

    3.초보 개발자를위한 설명서가있는 OpenCart Wiki 웹 사이트가 있습니다. 자세한 내용은 아래 URL을 참조하십시오.

    초보 개발자를위한 설명서가있는 OpenCart Wiki 웹 사이트가 있습니다. 자세한 내용은 아래 URL을 참조하십시오.

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

    예 : 메소드 참조에는 다음에 대한 세부 정보가 있습니다.

    아직 공사중 인 페이지가 있지만 도움이 될 것입니다.

    [최신 정보]

    2018 년 1 월 현재 opencarhelp.com 도메인이 다운되었습니다.

  4. ==============================

    4.PHP는 5000 개가 넘는 내장 함수가 포함 된 상당히 큰 언어이므로 새로운 플랫폼을 학습하는 한 가지 전략은 가장 자주 사용하는 함수를 식별하고 그 함수를 잘 이해하는 데 시간을 투자하는 것입니다.

    PHP는 5000 개가 넘는 내장 함수가 포함 된 상당히 큰 언어이므로 새로운 플랫폼을 학습하는 한 가지 전략은 가장 자주 사용하는 함수를 식별하고 그 함수를 잘 이해하는 데 시간을 투자하는 것입니다.

    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/

  5. from https://stackoverflow.com/questions/13478995/how-to-become-an-opencart-guru by cc-by-sa and MIT license