Posts

create subdomains using htaccess

Its very quick and easy. Here we go You need to create a wildcard domain on your DNS server *.website.com  Then in your vhost container you will need to specify the wildcard aswell *.website.com - This is done in the ServerAlias DOCs  Then extract and verify the subdomain in PHP and display the appropriate data Here we go in some detail. Create a wildcard DNS entry -  In your DNS settings you need to create a wildcard domain entry such as *.example.com. A wildcard entry looks like this:  *.example.com.   3600  A  127.0.0.1 Include the wildcard in vhost -  Next up in the Apache configuration you need to set up a vhost container that specifies the wildcard in the ServerAlias DOCs directive. An example vhost container: <virtualhost> ServerName server.example.com ServerAlias *.example.com UseCanonicalName Off </VirtualHost> Work out which subdomain you are on in PHP - Then in your PHP scripts you can find out t...

Drupal 8 with symfony

We all know that Symfony is already in the core of Drupal 8 but how it works and how both systems work? Not that many people understand fully this integration. Me neither but I would like to pubilsh my research notes about how Drupal 8 works now. Surely this material is based on the snapshot of beginning September and I really hope that more things will happen so this information is relevant only for some time. I have little experience of the building projects with Symfony so my knowledge is very close to majority of drupal developers. So lets start. First changes we see in index.php that bootstrap is done on the level of DRUPAL_BOOTSTRAP_CODE instead of DRUPAL_BOOTSTRAP_FULL like in Drupal 7. From documentation about phases of bootstrap of Drupal 8 we can see that phase that "initialize language, path, theme, and modules" is not done yet. Next thing we see that we instantiate object of the DrupalKernel class (inherits from Symfony Kernel class) Kernel class in Symf...

How does caching work in Drupal?

Image
In my experience, there seems to be a lot of misunderstanding how Drupal caching works. I'm not talking about advanced caching mechanisms like Varnish, APC or memcache here, I'm talking about the core Drupal caching: page cache and block cache which are available in Drupal 7 core. Drupal 6 is similar but works a but differently because page caching was simplified for Drupal 7 (e.g. aggresive mode is now a available as a settings.php var) and the entire system also has become pluggable. Everybody knows this screen and the settings. But what do they exactly mean? What difference do they actually make? What do they do? Here is an attempt to explain the settings at '/admin/config/development/performance' . Page Caching: If enables, page caching will only be used for anonymous users. If you enable page caching, the entire HTML of each page will be stored in the database. This significantly reduces the amount of queries needed. This automatically means that bl...

Theming Views 2 – The Basics

Image
Views 2 provides a well structured theming environment allowing presentation control for each element of your view. And in my humble opinion, it rocks! Those with no past experience with Views 1 will find Views 2 uses standard PHPTemplate theming techniques. All of your experience theming Drupal can be used with Views. Views 1 themers starting with Views 2 might be a bit confused at first. I was. The single callback in template.php where everything happened is gone, refactored into a consistent framework of template files. All of the freedom that existed in the single function still exists with the added benefit of a well defined structure Overview: Views handles querying the database and organizing the information for display. It creates the output display by converting retrieved data into variables and passing them through a series of templates. Each template handles a different "level" of output creation. The number of templates used to create a view's output depen...

Drupal Bootstrap Database

This is the 3rd article in the series covering DRUPAL v6 bootstrap process. As the bootstrap name implies, this phase covers initializing a connection to a database. The phase begins by including 'database.inc' , which is a database abstraction layer allowing developers to use different database servers with the same code base. One of the functions defined by this library is the db_set_active() function, which is invoked by the bootstrap database phase. This function is used to activate a database used by queries in later phases or during page building and rendering. The function begins by checking if the global variable $db_url is empty. Recall that in the phase #1 - DRUPAL_BOOTSTRAP_CONFIGURATION, this variable is set to the value specified in settings.php unless it is still set to the default string of ' mysql://username:password@localhost/databasename' . In that case, $db_url is simply set to empty string ''. This would indicate a first time insta...

get XML Namespace Elements using PHP SimpleXML

PHP has a great SimpleXML library that converts XML to an object that can be processed with normal property selectors and array iterators. I’ve been using this quite a bit lately to process some XML documents. The library documentation isn’t that great when it comes to processing Namespace Elements within your XML document. An example of such use case is when you are parsing an RSS feed that has XML Namespace elements . Consider the following example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?xml version = "1.0" encoding = "UTF-8" ?> <rss version = "2.0" xmlns:opensearch = "http://a9.com/-/spec/opensearch/1.1/" xmlns:dc = "http://purl.org/dc/elements/1.1/" > <channel > .... <item > <title > My Title </title > <description > My Item </description > <dc:publisher > ABC </dc:publisher > <dc:creator > DEF </dc:creator > <dc:date ...

Drupal bootstrap early page cache

The previous article in this series focused on phase 1 of the Drupal bootstrap process (DRUPAL_BOOTSTRAP_CONFIGURATION). This article will now focus on the second phase - DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE. The early page cache phase is one that might not accomplish much for some Drupal sites, but for some others can play an important role in improving a site's overall performance by minimizing latency when delivering content to a user's browser. This is accomplished by caching already rendered pages for anonymous users (i.e. haven't logged in). This phase is run early in the bootstrap process as it doesn't rely on any later bootstrap phases (used to gather content and render pages) and its purpose is to keep latency to a minimum - in other words the sooner it executes, the faster a user receives the requested content. There are two forms of caching with Drupal: non-database and database. The early page cache relies on non-database mechanisms, such as file syst...