Chuyển đến nội dung chính

Dev Tips #Rewrite Prevent duplicate request AJAX when rewrite in Magento

RewriteRule . /index.php [L]
# skip POST requests
RewriteRule ^ - [L]

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteRule ^index.php/admin/(.*)$ /admin/$1 [L,R]

Rewrite xóa index.php trên url bằng htaccess

Nhận xét

Bài đăng phổ biến từ blog này

Add external lib to vendor Magento 2

Magento 2 use autoload implement Code style PSR-4

You can add any custom source lib much easier by add require autoload

1. Upload lib files to vendor dir

2. Add file autoload.php in /vendor/lib-folder/autoload.php with content
define('FACEBOOK_SDK_V4_SRC_DIR', '/src/Facebook/'); require __DIR__ . '/src/Facebook/autoload.php'; 3. Save and now you can call lib from anywhere
like this
---- Injection from constructor and call instance in class

GetUrl in Magento 2

review file \Magento\Store\Model\Store.php

public function getBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LINK, $secure = null) { $cacheKey = $type . '/' . ($secure === null ? 'null' : ($secure ? 'true' : 'false')); if (!isset($this->_baseUrlCache[$cacheKey])) { $secure = $secure === null ? $this->isCurrentlySecure() : (bool)$secure; switch ($type) { case \Magento\Framework\UrlInterface::URL_TYPE_WEB: $path = $secure ? self::XML_PATH_SECURE_BASE_URL : self::XML_PATH_UNSECURE_BASE_URL; $url = $this->getConfig($path); break; case \Magento\Framework\UrlInterface::URL_TYPE_LINK: $path = $secure ? self::XML_PATH_SECURE_BASE_LINK_URL : self::XML_PATH_UNSECURE_BASE_LINK_URL; $url = $this->getConfig($path); …

How to load Javascript scripts in Magento 2

All assets file relate in frontend will be store in view/web of module structure

Require lib from requirejs-config.js file

var config = { map: { "*":{ "lightbox": "VES_Sociallogin/js/lightbox/lightbox.min" //This related to file lightbox/lightbox.min.js } } };
Order to call light box js

In any js files you can call to like this. You should use define instead of require in stituation

define([ "jquery", "jquery/ui", "lightbox", 'Magento_Ui/js/modal/alert', 'uiComponent' ], function($, lightbox, alert, uiComponent){ "use strict"; $(window).ready(function(){ //console.log('hello magento2! File js edited'); DO ANY CODE YOU WANT HERE }); });
Execute js in template mangeto can be done with script tag
script tag with type="text/x-magento-init" { "*":{ "VES_Sociallogin…