Posts

connect to multiple database from drupal

Drupal has the ability to connect to multiple databases, allowing you to use Drupal’s built in database abstraction layer on more than just Drupal's primary database. Preferably you would add your configuration in the settings.php file for your site, so that all modules can interact with the new database. Drupal 7 In your settings.php: $databases = array(); $databases['default']['default'] = array( // Drupal's default credentials here. // This is where the Drupal core will store it's data. ); $databases['alternate_db']['default'] = array( // Your secondary database's credentials here. // You will be able to explicitly connect to this database from your modules. ); The way to use it in module: // Use the database we set up earlier db_set_active('alternate_db'); // Run some queries, process some data db_query('...............'); //Switch back to the default connection when finished. // other...

create and execute a command in symfony 2

In Symfony 1.x a task is a command line tool to help perform tasks around the application. The same is in Symfony 2. Unfortunately in Symfony2 there is no tool to auto-generate some code for these. To create a Symfony2 Command you must to have or to create in your Bundle a folder named Command. Symfony 2 is mainly used to create web application, however, sometimes you need to extend your app and need a command line tool to help perform tasks around the application. It's one of the most stable parts of the framework and many people have already been using it for several months in many projects as it makes it really easy to develop this kind of software. And of course, everything is done in a really cool way, as many of the parts of Symfony2. Let’s see how can extremely easy create a new Command Task and custom our output. Create a file in Command Folder, for instance NewsletterCommand.php and fill it with an empty Command structure as follows <?php namespace Ankit\News...

how to use claim token in technorati

It's very easy to verify your blog using claim token in technorati. although technorati doesn’t show you how to claim your token to verify your blog in technorati. Here I’m going to tell you how to verify your blog listing in technorati using claim token. after creating an account in technorati, you recieve a mail having the text following from them. This is an automatically-generated email. Thank you for submitting your blog claim on Technorati . Technorati will need to verify that you are an author of the site http://ankitchauhan22. blogspot.in by looking for a unique code. We have just assigned the claim token ############## to this claim. Please visit http:// technorati .com/account/ for more details, including how to use the claim token. Follow these steps to verify your blog using claim token. Create a new post (such as this) using your blog panel. Copy the claim code from your email. Paste your 12-digit technorati claim token in the body of the post....

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...