Friday 25 July 2014

How to create Yii Web application and new info about Yii Framework

About Yii
Yii is a high-performance PHP framework best for developing Web 2.0 applications.
Yii helps Web developers build complex applications and deliver them on-time.
Yii is pronounced as Yee or [ji:], and is an acroynym for "Yes It Is!".
Yii 1.1 is the latest stable version.
The latest version of Yii 2 is 2.0.0 beta, released on April 13, 2014.
Yii 2.0 is not ready for production use yet. It is currently under heavy development.

How to set up yii web application in localhost.

1. Down load the latest yii framework (yii version1.1) from below link
   http://www.yiiframework.com/download/

2. Extract the code from zip or gaiz file,
you will get following folders,
demos
framework,
requirements
and following four files
CHNAGELOG
LICENSE
README
UPGRADE

3. Put all files to the root level in you localhost.
for the xampp user they can place these files under the htdocs folder.

4. run the below code for create the yii app (project)
Create Yii Project In Local Host With Xampp Using Command Line
Step 1 open command line
Step 2 run below command it will create all the default structure for the project.
Here "newyiiprojectname"  is the name of the folder(project) you want to create. you can change it as per your choice.
C:\xampp\php>php C:/xampp/htdocs/framework/yiic.php webapp C:\xampp\htdocs\newyiiprojectname
once you run above command it will ask you to create a web application under the defined path with yes/no option.
here if you type yes and press enter it will create the new yii app(project) with the given folder name.

Now your application is ready. You can access it by using following link
http://localhost/newyiiprojectname/


How to setup yii project in localhost

Create Yii Project In Local Host With Xampp Using Command Line

Step1 open command line

Step 2 run below command it will create all the default structure for the project.

here "newyiiprojectname"  is the name of the folder(project) you want to create. you can change it as per your choice.
C:\xampp\php>php C:/xampp/htdocs/framework/yiic.php webapp C:\xampp\htdocs\newyiiprojectname

Friday 18 July 2014

How to hide index.php from url in yii

URL rewriting in Yii to hide index.php

To hide the index.php from url you have to make the changes in config/main.php  as shown below,
‘urlManager’=>array(
                              ‘urlFormat’=>’path’,
                              ‘showScriptName’=>false, //this option will be hide the index.php from url
                              ‘rules’=>array(
                                                ‘<controller:\w+>/<id:\d+>’=>’<controller>/view’,
                                               ‘<controller:\w+>/<action:\w+>/<id:\d+>’=>’<controller>/<action>’,
                                              ‘<controller:\w+>/<action:\w+>’=>’<controller>/<action>’,
                                             ),
), 
and create new .htaccess file in the same directory as my index.php file shown as below,
RewriteEngine  On
RewriteBase  /
RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond   %{REQUEST_FILENAME} !-d
RewriteRule    ^(.*)\?*$ index.php/$1 [L,QSA]
You can change the ”RewriteBase /’  as per project location like if project is located in ‘abc/′ of webroot.
then it change like as    RewriteBase  /abc

That will make sure your auto-generated links (CHtml::link or zii.widgets.CMenu) do not have index.php in them. This will not work without the .htaccess file. The reason is that the .htaccess file rewrites the url to point to index.php/$1 so that Yii actually gets the request properly. You will not see the index.php in the url at any time though.

How to calculate the weeks between two dates

How to calculate the weeks between two dates.

//php code
$today=date('Y-m-d h:i:s');
$fromData="2014-01-01 00:00:00"
$diff = strtotime($today, 0) - strtotime($fromData, 0);
$weekNo = floor($diff / 604800);
$weekNo = $weekNo+1;
echo "This is the ".$weekNo." of the Year 2014";
//end

Friday 4 July 2014

How to Get Customer billing and shipping information

# Getting customer billing address information
$quote = Mage::getSingleton(‘checkout/session’)->getQuote();
$billingAddress = $quote->getBillingAddress();
$country = $billingAddress->getCountryId();
$city = $billingAddress->getCity();
$zipcode = $billingAddress->getPostcode();

# Get customer default billing information
$customerAddressId = Mage::getSingleton(‘customer/session’)->getCustomer()->getDefaultBilling();
if ($customerAddressId){
$address = Mage::getModel(‘customer/address’)->load($customerAddressId);
$address->getData();
}

# Get customer default shipping information

$customerAddressId = Mage::getSingleton(‘customer/session’)->getCustomer()->getDefaultShipping();
if ($customerAddressId){
$address = Mage::getModel(‘customer/address’)->load($customerAddressId);
$address->getData();
}

How to Create new Customer billing and shipping address

$_custom_address = array (
    'firstname' => 'Sanjay',
    'lastname' => 'Rao',
    'street' => array (
        '0' => 'Line address part1',
        '1' => 'Line address part2',
    ),
    'city' => 'Ahemdabad',
    'region_id' => '',
    'region' => '',
    'postcode' => '380015',
    'country_id' => 'IN', /*India */
    'telephone' => '1234567890',
);
$customAddress = Mage::getModel('customer/address')
$customAddress->setData($_custom_address)
            ->setCustomerId($customer->getId())
            ->setIsDefaultBilling('1')
            ->setIsDefaultShipping('1')
            ->setSaveInAddressBook('1');
try {
    $customAddress->save();
}
catch (Exception $ex) {
    //Zend_Debug::dump($ex->getMessage());
}

How to Create new Customer in magento or update customer info in magento

$customer = Mage::getModel('customer/customer');
$password = '123456';
$email = 'sanjay@rao.com';
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);

if(!$customer->getId()) {
    $customer->setEmail($email);
    $customer->setFirstname('Sanjay');
    $customer->setLastname('Rao');
    $customer->setPassword($password);
}
try {
    $customer->save();
    $customer->setConfirmation(null);
    $customer->save();
    //Make a "login" of new customer
    Mage::getSingleton('customer/session')->loginById($customer->getId());
}
catch (Exception $ex) {
    Zend_Debug::dump($ex->getMessage());
}



How to Get All State List In Magento for specific country

//below code load all the State  of US
$countryCode= ‘US’;
$states = Mage::getModel('directory/country')->load($countryCode)->getRegions();
$slist= array();
foreach ($states as $state) {
$sid = $state->getId();
            $sname = $state->getName();
            $slist[$sid]=$sname;                                                              
}

asort($slist);

How to Get All Country List In Magento

$clist= array();
$collection = Mage::getModel('directory/country')->getCollection();
foreach ($collection as $country){
$cid = $country->getId();
            $cname = $country->getName();
            $clist[$cid]=$cname;
}

asort($clist); // sort country list 

How to Get Customer Default Shipping Detail Using Customer Id in Magento

If you know the customer id than direct use it other wise first you can get customer id than use that.

$customerId =2; // already known

Mage::getSingleton('customer/session')->loginById($customerId);
$customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping();
$address = Mage::getModel('customer/address')->load($customerAddressId);
$address_data = array (
            'prefix' => $address->getPrefix(),
            'firstname' => $address->getFirstname(),
            'lastname' => $address->getLastname(),
            'street' => $address->getStreet(),
'city' => $address->getCity(),
            'region_id' => $address->getRegionId(),
            'region' => $address->getRegion(),
            'postcode' => $address->getPostcode(),
            'country_id' => $address->getCountryId(),
            'telephone' => $address->getTelephone(),
            'email' => $address->getEmail()

);

How to Get Customer Detail Using Email Id in Magento

$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId()); 
$customer->loadByEmail($customer_email);
//get customer id
$customerId = $customer->getId();
//get customer Email
$customerEmail = $customer->getEmail ();
//get customer First Name
$fname = $customer->getFirstname();
//get customer Last Name
$lname = $customer->getLastname();
//get customer Full Name
$fullname = $customer->getName();

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...