Posts

Showing posts from 2013

create filter in controller symfony2

Sometimes you need to make changes to the Response object, after it is returned by your controller, but before it is rendered as output to the client (e.g. the browser). You may want to set some extra response headers, or " completely mess up the content " of the response. You can accomplish this by creating an event listener that listens to the kernel.response event. I give you a sample event listener which changes the Content-Type header in case the requested format is json and the browser’s accepted response format contains "text/html" in that case, at least in my experience, the browser doesn’t render the JSON string as plain text when the status code is 4xx or 5xx. So in these situations, the event listener changes the “ Content-Type ” to “ text/plain ”, to be sure you always get decent output in the browser. Put the event listener in, for example /src/Acme/DemoBundle/EventListener/ResponseListener.php : namespace Acme\DemoBundle\EventListener;...

remove non ASCII characters from a String

Hi guys I had a problem with removing non-utf8 characters from string, which are not displaying properly. Characters are like this 0x97 0x61 0x6C 0x6F (hex representation). I am getting some encoded value from url. Let assume it's encoded email and value is ankitchauhan22@gmail.com When I tried to find out the length of this string as $email = somefunction($encodedStringFromUrl); $length = strlen($email); print $length; I was shocked. It's printing 37 instead of 24. Than I printed each index of this string on the string but after 24 character, nothing printed. I used trim() to remove whitespace but didn't work. Then I tried something which worked for me. This is a little snippet that will remove any non-ASCII characters from a string. $string = "ankitchauhan22@gmail.com äó"; $string = preg_replace('/[^(\x20-\x7F)]*/','', $string); Now It's printing 24.

jQuery & JavaScript PDF Viewer plugin

Image
Hi guys In this Post I'm providing best jQuery PDF viewer plugin & tutorial with examples. Due to popularity of online document viewer like Google Docs some javascript developers develop a good and useful plugins to view pdf file on online pdf viewer.Here is some good list of online pdf viewers. JavaScript PDF Reader : pdf.js It's an HTML5 experiment that explores building a faithful and efficient PDF renderer without native code assistance. Read More Demo jQuery Media Plugin The jQuery Media Plugin supports unobtrusive conversion of standard markup into rich media content. It can be used to embed virtually any media type, including Flash, Quicktime, Windows Media Player, Real Player, MP3, Silverlight, PDF and more, into a web page and is compatible with all web hosting services The plugin converts an element which holds the object, embed iframe tags neccessary to render the media content. Demo PDFObject : Embeds PDF files into HTML documents A JavaScript ...

css3 tips and tricks collection

You can never have too much of a good thing–and two good things we rely on in our work are tips and tricks. Nuggets of information, presented clearly and succinctly, help us build solutions and learn best practices. CSS level 3 has been under development since December 15, 2005. CSS3 is modularized and consists of several separate recommendations. CSS3 is one of the more exciting and versatile developments for the web in some time. In this article I am going to create a huge list of CSS3 Tips, Tricks and Tutorials for Web Developers. Useful Link : Be updated with these Featured Table Design With CSS3 Basic CSS3 Techniques That You Should Know CSS3 Animated Bubble Buttons How To Create CSS3 Christmas Tree Ornaments Quick Tip : New HTML5 Form Features The State Of CSS3 In Email Templates CSS3 Transition Tutorial – Menü mit Slide-Effekt im Apple-Style Semantic CSS3 Lightboxes Creating A Realistic Looking Button With CSS3 CSS3 Gradient Buttons Pure CSS3 Speech Bubbles Sha...

speed up symfony2 application with varnish

Hi everyone, Just a quick note about Varnish integration for symfony. I’m sure you have heard of Varnish reverse proxy server. Varnish is a web accelerator written with performance and flexibility in mind. It’s modern architecture gives it a significantly better performance than many of it’s competing products. Varnish store web pages in memory so the web servers don’t have to create the same web page over and over again. The web server only recreate a page when it is changed. Additionally Varnish can serve web pages much faster then any application server is capable of – giving the website a significant speed up. So in first order you may be interested to integrate Varnish to handle pages which don’t require authentication (for myself I’m still not sure if there is any advantage for integrating pages for logged in users): sub vcl_recv { set req.http.Surrogate-Capability = "abc=ESI/1.0"; } sub vcl_fetch { if (beresp.http.Surrogate-Control ~ "ESI/1.0...

Creating a PrestaShop module

Image
A PrestaShop module consists of: A root folder, named after the module, which will hold all of the module's files, and will reside in PrestaShop's /modules folder. A main PHP file, named after the module, located in that root folder. This PHP file should have the same name as its root folder. An icon file, named logo.gif, representing this module. Optional: some .tpl files, containing the module's theme. Optional: language files, if the module or its theme have text to display (and therefore, that should be translatable). Optional: in a /themes/modules folder, a folder with the same name as the module, containing .tpl and language files if necessary. This last folder is essential during modifications of existing module, so that you can adapt it without having to touch its original files. Notably, it enables you to handle the module's display in various ways, according to the current theme. Now I am going to create a module named Testmodule. Your module can b...

Styling Progress Bar With HTML5

Image
0% Reload HTML5 introduced the progress bar element, which allows us to show the progress of certain tasks, like uploads or downloads, basically anything that is in progress Basic Usage The progress bar can be added with <progress> ; the progress value is determined with the value, min and max attributes, as follows. <progress value="40" max="100"></progress> Since this is a native progress bar, the presentation is vary dependent on the platform. Below is how a native progress bar looks in Windows and OSX. Now, let's try styling this progress bar, so it has a consistent or similar look across all platform. Styling Progress Bar In the stylesheet, we actually can use the element selector to target and add style rules to <progress> element. In this example, we change the background color, remove the border line, and make it rounded by adding a border radius at half of its height. progr...

creating stick stylish button using css3

CSS3 is rapidly expanding the toolkit that web developers and designers have to make visually appealing components without the use of images, Photoshop, or CSS sprites. While all of those have their place, and will never be completely removed from the development process, buttons are one component of a website that we can make dynamic, slick and scalable – exclusively in code. All of the CSS3 buttons that we create today will be styled forms of anchor tags. Some like to use button elements for these, but I find it’s easiest to use anchor tags so you can easily add the :hover and :active pseudo classes and quickly add href to it to complete the button. What We're Creating For this tutorial, we’ll be creating several different CSS3 buttons, all of which can have different colors, shadows, sizes – all using pure CSS3. We will be using the following properties: border-radius , linear-gradient , box-shadow , text-shadow and opacity . you might want to change some of these ...

Controllers as Services in Symfony2

Controller as a service is continually touted as the best practice. But why would I wrap a controller into a service? That's good question. Well, the point of doing this in general is not having to inject the DI container into your controllers (instead, you inject the dependencies into the controller directly). Thus the controller no longer depends on the container. Good: You get added flexibility. You no longer hard-code which services to use into your controller. You can specify that in the DI configuration instead. Example: You inject a UserProvider into the UserController for /profile, but inject a FacebookUserProvider into the same UserController for /profile/facebook. Bad: You must manually configure your dependencies in the DIC config. You need to manually assign the injected dependencies. Optional dependencies are no longer lazy-loaded. This is basically just a proof of concept to show how it could be done. namespace Acme\DemoBundle\Controller; class FooContr...

run symfony command from controller

Hi Friends, Few month back I was trying to execute Symfony2 command in my controller. See how can we do that. Step 1 Register you command as service MyCommandService: class: MyBundle\Command\MyCommand calls: - [setContainer, ["@service_container"] ] Step 2 In your controller, you'll just have to get this service, and call the execute method with the rights arguments. Set the input with setArgument method: use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; . . . public function myAction() { $command = $this->get('MyCommandService'); $input = new ArgvInput(array('arg1'=> 'value')); $output = new ConsoleOutput(); $command->run($input, $output); } Step 3 Either you can use the execute method of command: $command->execute($input, $ouput); But see the defination of run() and execute() methods. run () -: The code to ...

protecting php file with ionCube encoder

One of the issues PHP developers face is that PHP is an interpreted language, meaning PHP source code is readable by anybody who downloads your applications. In this article I will show you how to protect your intellectual property by encoding your PHP source code. The tool we are going to use to protect our code is ionCube PHP Encoder . Before releasing your PHP software, you use the encoder to convert your plain-text PHP files into special encrypted files. While ionCube PHP Encoder is a commercial product, there is a time-limited trial available for download . Because your PHP is encoded into a special byte-code (as opposed to just being obfuscated), a loader must be installed on your web server. A loader is a PHP module that must be installed. Fortunately, ionCube PHP Encoder is commonly used and therefore many web hosts will already have a loader installed. On the ionCube website there is a loaders page which contains the latest versions of the loader for all supported plat...

multiple cron job using same file

Hi guys, Today I am posting something about cron. 1 year back, I was getting some trouble in my project in scheduling cron. I had lots of task to be managed by cron, for that I was making multiple files. But after some research I managed those task by a single file. If your cron job accomplish similar tasks or requires the same libraries you will have to include the same files over and over to all your cronjobs ... or use this solution. Let say you have these cron jobs: 0 1 * * * /etc/lib/php -q /home/user/cron/cron1.php 15 1 * * * /etc/lib/php -q /home/user/cron/cron2.php 30 1 * * * /etc/lib/php -q /home/user/cron/cron3.php 0 2 * * * /etc/lib/php -q /home/user/cron/cron4.php And each of these cron jobs perform different tasks but use the same libraries like phpmailer, pdf creator, geoip, payment verification etc... The idea is simple, separate tasks or commands using parameters: 0 1 * * * /etc/lib/php -q /home/user/cron/cron1.php --task=task1 15 1 * * * /etc/lib...

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