Installing and Configuring Symfony2 framework on Linux Ubuntu OS

In this article, I'm going to explain about How to Install and configure Symfony 2 framework on Linux Ubuntu operating system. Here I have explained step by step procedure to install and configure Symfony 2 framework on linux ubuntu operating system.

Step 1:

The below are required to run symfony framework on linux ubuntu operating system.
  • PHP 5.3.2
  • Apache Webserver.
  • MySql Database.
  • Sqllite 3 needs to be enabled.
  • JSON needs to be enabled
  • ctype needs to be enabled
  • Your PHP.ini needs to have the date.timezone setting
Step 2:

Download the Symfony framework from http://symfony.com/download and place the tgz folder inside your web root, i.e, /var/www/

Step 3:

Extracts the contents of the folder and rename the folder like "my_symfony_project"

Step 4:

After placing the code, go to http://localhost/my_symfony_project/web/config.php to check whether everything is working fine or not.

Step 5:

Go to http://localhost/my_symfony_project/web/config.php to access your Symfony framework project welcome page. You will see screen like below once you have successfully installed Symfony2 instance.


Now, Symfony2 instance is up and running in your local machine. Drop comments if you have difficuly in setting up instance.

Magento - Creating and accessing An External Database Connection

In this article I'm going to explain about How t create and access an external database connection in Magento. Most of the developers facing some troubles when trying to create and access the external database connection in Magento. This article will help the developers to reach their goals by creating and accessing the external database connection in Magento.

Step 1 : Creating the database connection

To create the external database connection you need to create a custom module and add the following code to your config.xml. The code is used to get the external database connection to be work.

<?xml version="1.0"?>
<config>
    <modules>
        <Phpcmsframework_Externaldb>
            <version>0.1.0</version>
        </Phpcmsframework_Externaldb>
    </modules>
    <global>
        <resources>
            <externaldb_write>
                <connection>
                    <use>externaldb_database</use>
                </connection>
            </externaldb_write>
            <externaldb_read>
                <connection>
                    <use>externaldb_database</use>
                </connection>
            </externaldb_read>
            <externaldb_setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </externaldb_setup>
            <externaldb_database>
                <connection>
                    <host><![CDATA[localhost]]></host>
                    <username><![CDATA[db_username]]></username>
                    <password><![CDATA[db_password]]></password>
                    <dbname><![CDATA[db_name]]></dbname>
                    <model>mysql4</model>
                    <type>pdo_mysql</type>
                    <active>1</active>
                </connection>
            </externaldb_database>
        </resources>
    </global>
</config>

After adding the above code to your config.xml, clear the cache and from now on, each time you load Magento, a second database connection will be created.

Step 2: Accessing the Database

You can use the following Zend_Db to test your database connection is working or not.

<?php
     $resource   = Mage::getSingleton('core/resource');
    $conn       = $resource->getConnection('externaldb_read');
    $results    = $conn->query('SELECT * FROM tblName');     
    print_r($results)

This works fine, however kind of takes the point away from having this connection available in Magento.

Step 3: Accessing The External Database Using Models

Using models to access the database keeps our code style uniform throughout Magento. Also, it means we can integrate any other CMS or database driven application without learning it's coding practices. To achieve this, simply add models to your custom module like you would for any other module.

Create the following files

code/local/Phpcmsframework/Externaldb/Model/Book.php

<?php
class Phpcmsframework_Externaldb_Model_Book extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        $this->_init('externaldb/book');
    }
}

code/local/Phpcmsframework/Externaldb/Model/Mysql4/Book.php

<?php
class Phpcmsframework_Externaldb_Model_Mysql4_Book extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {
        $this->_init('externaldb/book', 'book_id'); // book_id refers to the primary key of the book table
    }


code/local/Phpcmsframework/Externaldb/Model/Mysql4/Book/Collection.php

<?php
class Phpcmsframework_Externaldb_Model_Mysql4_Book_Collection extends Mage_Core_Model_Mysq4_Collection_Abstract
{
    public function _construct()
    {
        $this->_init('externaldb/book');
    }
}

Adding the Models to The Config

To inform Magento about our models, we need to register them in config.xml. Below is an updated version of config.xml with the models for Book registered.

<?xml version="1.0"?>
<config>
    <modules>
        <Phpcmsframework_Externaldb>
            <version>0.1.0</version>
        </Phpcmsframework_Externaldb>
    </modules>
    <global>
        <models>
            <externaldb>
                <class>Phpcmsframework_Externaldb_Model</class>
                <resourceModel>externaldb_mysql4</resourceModel>
            </externaldb>
            <externaldb_mysql4>
                <class>Phpcmsframework_Externaldb_Model_Mysql4</class>
                <entities>
                    <book>
                        <table>library_book</table>
                    </book>
                </entities>
            </externaldb_mysql4>
        </models>
        <resources>
            <externaldb_write>
                <connection>
                    <use>externaldb_database</use>
                </connection>
            </externaldb_write>
            <externaldb_read>
                <connection>
                    <use>externaldb_database</use>
                </connection>
            </externaldb_read>
            <externaldb_setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </externaldb_setup>
            <externaldb_database>
                <connection>
                    <host><![CDATA[localhost]]></host>
                    <username><![CDATA[db_username]]></username>
                    <password><![CDATA[db_password]]></password>
                    <dbname><![CDATA[db_name]]></dbname>
                    <model>mysql4</model>
                    <type>pdo_mysql</type>
                    <active>1</active>
                </connection>
            </externaldb_database>
        </resources>
    </global>
</config>

Testing The Models

Testing them is easy enough, just treat them like normal Magento models.

<?php
    // Load the book with a primary key value of 4
    $_book = Mage::getModel('externaldb/book')->load(4);

    // This would print out the value in the field isbn in the external database
    echo $_book->getIsbn();

    //You can even update records!
    $_book->setName('1984');
    $_book->setAuthor('George Orwell');

    try {
      $_book->save();
    } catch (Exception $e) {
      exit($e->getMessage());
    } 

Download Dropbox Component and Plugin for Joomla 1.5 and Joomla 2.5

With this Dropbox component you can connect joomla to www.dropbox.com or www.sugarsync.com. You can publish files, view the pictures in a directory and let users upload files to dropbox / sugarsync.

You can use the extension as a component or as a plugin

Version 1.x is for Joomla 1.5.x version 2.x is for Joomla 1.6 and 1.7

Caution!: The version for Joomla 1.6 / 1.7 is still beta - please report problems in the forum

NEW: since 2.0_beta1 its possible to create private folders for every user

Requirements:
  1. PHP 5 >= 5.2.0 with PECL json >= 1.2.0
  2. cURL with SSL
  3. Joomla 1.5.x / 1.6.x / 1.7.x
Costs: You decide yourself how much you like to pay for the plugin (min 1,79 EUR)

To Download the Component and Plugin - Click Here

For Demo - Click Here

For Support - Click Here

For Documentation - Click Here

Codeigniter - Verify Captcha with Ajax

In this article, we are going to discuss about How to verify captcha with Ajax in CodeIgniter websites. Captcha is necessary to avoid spam. To avoid spam mails/accounts, we are using Captcha in forms. If we see with end user point of view, a user feel uncomportable when he/she has to give a right verification code and also have to receive an error message if it is wrong. If we use ajax to verify the captcha, it reduces the user's troubles.

We can check captcha on blur event or on submitting a form and alert the user about invalid code entered.

Here I have mentioned some steps to add captcha in your form and How to verify that captcha with Ajax in Codeigniter.

Step 1 : 

Use the below code to show captcha in Codeigniter (CI).

function Ajax_captcha(){
var code = $("#code").val(); // get the code entered 
if(code.length>1){
$('#Loading').show(); // show the loader image
$.post("<?php echo base_url()?>Site/Ajax_Captcha",{
code: $('#code').val()
}, function(response){
$('#Ifno').fadeOut();
setTimeout("RemoveAJAXCaptcha('Info', '"+escape(response)+"')", 400);
});
}
return false;
}
// this function will hide the loader image and show the result as inner html 
function RemoveAJAXCaptcha(id, response){
  $('#Loading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}

Step 2:

Add the below code in your HTML.

<input id="code" name="code" type="text" value="" onblur="return Ajax_captcha();" />
<span id="Info"></span>
<span id="Loading">
<img src="<?php echo base_url()?>images/loader.gif" alt="" />
</span>

Step 3:

Add the below code in your controller file.

function Ajax_Captcha($code,$this->session->userdata('yourSessionVarOfCaptcha'))
{
  if ($code==strtoupper($this->session->userdata('yourSessionVarOfCaptcha')))
  {
       return true;
  }
  else
  {
      return false;
  }
}

I hope this article may helpful for you to add and verify the captcha with Ajax in CodeIgniter.

Magento - Resize images using Varien_Image class

In this article, We are going to discuss about How to resize the images in Magento using "Varien_Image" Class. Magento also having the in-built library to resize the image in height and width. You can resize the product images using catalog helper. If you want to upload and resize the images which are not uploaded for product, then this article will help you to how to resize images, such as needing to resize a custom image and display it on the site in special sized areas.

Here I have mentioned the code to resize the images using "Varien_Image" class. This code resizes the images from a specific directory/folder and save the resized image to some other directory/folder.

$_imageUrl = Mage::getBaseDir(‘media’).DS.$image;
$imageResized = Mage::getBaseDir(‘media’).DS.“resized”.$image;
if (!file_exists($imageResized)&&file_exists($_imageUrl)) :
$imageObj = new Varien_Image($_imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(140, 140);
$imageObj->save($imageResized);
endif;

Hope this article will work for you.

Joomla - Register new component into database

In my previous articles, I have explained about How to create front end component and also How to create a back end component in Joomla. In this article, We are going to discuss about How to register the new component into database. The purpose of registering the component into database is to publish the component in the component menu and also it can e choosen as the menu item type.

Here are the steps to register the component into database in joomla.

Step 1:
Open the "phpmyadmin" in your browser using "http://localhost/phpmyadmin/".

Step 2:
Select your "joomla" database from the list.

Step 3:
Find the "jos_components" table from the list of tables present in your database.

Step 4:
Find the "insert" tab. Check the below image. click on the "insert" tab.


Step 5:
When you click on the "insert" you will get the form like the below image.

Step 6:
After entering all the fields in "jos_components" table, Click on the GO button.

Step 7:
Now you can check the your joomla administrator components, to check whether it is succeeded or not.


My Previous posts related to this are.,

Create Back End Component in Joomla - Step by step procedure

Create Front End Component in Joomla - Step by step procedure

Upload and Convert video to FLV using FFmpeg in Codeigniter


In this article, we are going to discuss about How to upload and convert video into FLV format using FFMpeg in Codeigniter. FFMpeg commands are running only in Linux environment. If you want to use it in windows, you need download ffmpeg.exe file. Click here to download FFMpeg.exe. Download the FFmpeg executable file and place it in your root folder. If you are using Linux server, Use print phpinfo() function to check whether your hosting server has FFmpeg installed or you need it to be installed.

Use the below code for uploading and converting the video file in Codeigniter.

$file = 'video_file';
$config['upload_path'] = './video_folder/';
$config['allowed_types'] = 'mov|mpeg|mp3|avi';
$config['max_size'] = '50000';
$config['max_width']   = '';
$config['max_height']   = '';

$this->upload->initialize($config);
$this->load->library('upload', $config);

if(!$this->upload->do_upload($file))
{
// If there is any error
$err_msgs .= 'Error in Uploading video '.$this->upload->display_errors().'<br />';
}
else
{
$data=array('upload_data' => $this->upload->data());
$video_path = $data['upload_data']['file_name'];
  $directory_path = $data['upload_data']['file_path'];
$directory_path_full      = $data['upload_data']['full_path'];
$file_name = $data['upload_data']['raw_name'];

// ffmpeg command to convert video

exec("ffmpeg -i ".$directory_path_full." ".$directory_path.$file_name.".flv"); 

// $file_name is same file name that is being uploaded but you can give your custom video name after converting So use something like myfile.flv.

/// In the end update video name in DB 
$array = array(
'video' => $file_name.'.'.'flv',
);
$this->db->set($array);
$this->db->where('id',$id); // Table where you put video name
$query = $this->db->update('user_videos');
}