Tag Archives: code
scp command in linux to transfer files from one server to another
To transfer your files from one server to another use following command set. login to the server to which you have to copy the files(i.e. destination server) scp user1@server1:/full/path/to/source/file . Press enter it ll ask for the source server password.Provide … Continue reading
symfony form field without a label
I was standing in front of the problem that I have a form with only one field. In this case the label of the field has shown no sense. For this reason, it had gone – but how? The solution … Continue reading
Multiple domains on symfony project
This post is about developing a symfony project that provides multiple applications that are reachable on multiple top level domains. In our case, the symfony applications “UMTS Netzabdeckung” and “Flatrates Vergleich” share the same backend (models, data, etc.) but each site is a standalone application and has a dedicated top level domain.
Create two applications
The first step is to create two applications. Run
symfony generate:app site1
symfony generate:app site2
in your console and change the default actions, routing, etc. Same thing as usual.
Edit .htaccess
The next step is quite simple: Open your .htaccess file in /sf_project_dir/web and insert your second application to the .htaccess file (BEFORE the default RewriteRule)
RewriteCond %{HTTP_HOST} secondhost.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ site2.php [QSA,L]
That’s all!
That’s all to get it working. Each request to your second domain will be redirected to the according application. A drawback is, that your “frontend” application is still reachable on your second domain if you type in the script name directly. Since I’m not an htaccess expert, I just added some php code to my index.php:
if($_SERVER['SERVER_NAME'] != ‘www.flatratesvergleich.de’) {
header(‘Location: http://www.flatratesvergleich.de’ . $_SERVER['REQUEST_URI']);
die;
} Continue reading
Snippet: Symfony & Propel–Queries with SQL functions
This is a super short snippet that I ALWAYS forget how to do! Often I want to build more complex where clauses with Propel Criteria which use SQL functions such as UCASE, LCASE, LEN and the date functions DAY, MONTH and YEAR. This is possible using Propel & Criteria, but how to do it is not immediately obvious.
The snippet below shows how to select objects from the database which were created in a specific month and year. Using Criteria::CUSTOM, it’s possible to specify a column and a comparison to do with that column. This is quite useful for doing things like building archive lists.
$c->add(MyObjPeer::CREATED_AT, ‘MONTH(‘.MyObjPeer::CREATED_AT.’)=’. $month, Criteria::CUSTOM);
$c->addAnd(MyObjPeer::CREATED_AT, ‘YEAR(‘.MyObjPeer::CREATED_AT.’)=’. $year, Criteria::CUSTOM);
A Note on Snippets: When using frameworks such as Symfony it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, please let me know. Continue reading
How to Create Your First WordPress Plugin
Today I just explained the concept a wordpress plugin to one fo my mate @ workplace. So thought of documenting it here for my own reference. Example explained here is different than what i explained to my friend.
A WordPress plugin is simply one or more PHP files that adhere to certain rules and conventions. All you need to understand and complete this post is a basic understanding of PHP programming.
Aim of this post is to explain the concept of creating a Wordpress Plugin i.e. to explain the process for newbies.
Lets create a plugin which simply displays the most commented 5 posts.
Plugin Folder Structure
../wp-cpntent/plugin/your_plugin
Now we will create a folder in Wordpress Plugin directory say “most_commented_post” i.e.
../wp-cpntent/plugin/most_comments_on_post
Activating/Deactivating the Plugin
In order for wordpress to activate/deactivate we need to add PHP comments to main file of the plugin. Means we will create a file named “most_commented_post.php”
../wp-cpntent/plugin/most_comments_on_post/most_commented_post.p Continue reading
Symfony Coding Standards
Following coding standards is one of the easiest way for everybody to understand everybody’s code.Here’s the golden rule: Imitate the existing symfony code. Never use tabulations in the code. Indentation is done by steps of 2 spaces: <?php class sfFoo … Continue reading
Symfony:Forward vs Redirect
Forward vs Redirect? Symfony Redirect: This simply does a HTTP header(”location: “) Symfony Forward: This is complete custom code that comes with the Symfony framework that forwards you within the Symfony application. Use Symfony Forward if: If the action needs … Continue reading
Type confusions in Symfony
I post this merely to point out how easy it is to forget to check EVERYTHING when you appear to have a bug. I’ve been trying unsuccessfully for the last hour to save a string to my database, like $myString … Continue reading
Before And After Action in Symfony
Ever wanted to run some functions or create some variables before every action in a module? Or ever wanted to do something crafty after every action and before the template gets displayed? Even if your answer is no, its good … Continue reading


