Tuesday 20 June 2017

Disable Caching Drupal 8

1. Copy and rename the sites/example.settings.local.php to sites/default/settings.local.php:
$ cp sites/example.settings.local.php sites/default/settings.local.php
2. Open settings.php file in sites/default and uncomment these lines:
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {   
  include $app_root . '/' . $site_path . '/settings.local.php';
}
which used to be in previous D8 versions:
if (file_exists(__DIR__ . '/settings.local.php')) {
  include __DIR__ . '/settings.local.php';
}
This will include the local settings file as part of Drupal's settings file.
3. Open settings.local.php and uncomment (or add) this line to enable the null cache service:
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
By default development.services.yml contains the settings to disable Drupal caching:
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory
NOTE: Do not create development.services.yml, it exists under /sites
4. In settings.local.php change the following to be TRUE if you want to work with enabled css- and js-aggregation:
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
5. Uncomment these lines in settings.local.php to disable the render cache and disable dynamic page cache:
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
If you do not want to install test modules and themes, set the following to FALSE:
$settings['extension_discovery_scan_tests'] = TRUE;
6. Open development.services.yml in the sites folder and add the following block to disable the twig cache:
parameters:
  twig.config:
    debug: true
    auto_reload: true
    cache: false
NOTE: If the parameter block is already present in the yml file, append the twig.config block to it.
7. Afterwards you have to rebuild the Drupal cache otherwise your website will encounter an unexpected error on page reload. This can be done by with drush:
drush cr
or by visiting the following URL from your Drupal 8 website:
http://yoursite/core/rebuild.php
Now you should be able to develop in Drupal 8 without manual cache rebuilds on a regular basis.

Friday 31 October 2014

How to unset cookie in php?

A clean way to delete a cookie is to clear both of $_COOKIE value and browser cookie file :

if(isset($_COOKIE['key'])) {
  unset($_COOKIE['key']);
  setcookie('key', '', time() - 3600); // empty value and old timestamp
}

Wednesday 24 July 2013

Server-side JavaScript

The first incarnations of JavaScript lived in browsers. But this is just the context. It defines what you can do with the language, but it doesn't say much about what the language itself can do. JavaScript is a "complete" language: you can use it in many contexts and achieve everything with it you can achieve with any other "complete" language.
Node.js really is just another context: it allows you to run JavaScript code in the backend, outside a browser.
In order to execute the JavaScript you intend to run in the backend, it needs to be interpreted and, well, executed. This is what Node.js does, by making use of Google's V8 VM, the same runtime environment for JavaScript that Google Chrome uses.

Thursday 6 June 2013

sprintf in JavaScript

String.prototype.sprintf = function(a) {
    if (a.length) {
        var i = -1; // start at minus 1
        return this.replace(/\%(d|s|f)/gi, function(match, type){
            i++; // increment
            if (type == "d") return parseInt(a[i]);
            if (type == "f") return parseFloat(a[i]);
            if (type == "s") return a[i].toString();
        });
    }
}

var s = "Foo is %d times Blah which is %d. However, you might need %f %s";
console.log(s.sprintf([2, 4, "3.453", "shovels"]));

Thursday 23 May 2013

REPLACE(str,from_str,to_str)


Returns the string str with all occurrences of the string from_str replaced by the string to_str. REPLACE()performs a case-sensitive match when searching for from_str.
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
        -> 'WwWwWw.mysql.com'
This function is multi-byte safe.

Monday 6 May 2013

Json_encode

string json_encode ( mixed $value [, int $options = 0 ] )

Returns a string containing the JSON representation of value.

The value being encoded. Can be any type except a resourse
This function only works with UTF-8 encoded data.
 

Sunday 21 April 2013

What is PHP?

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

Disable Caching Drupal 8

1. Copy and rename the sites/example.settings.local.php to sites/default/settings.local.php: $ cp sites / example . settings . local . ph...