Home

Friday, January 11, 2013

Calling controller methods from inside view in Codeigniter

In controller:
function __construct()
{
    parent::__construct(); 
    $this->method_call =& get_instance();
}  
function checkChildExists($parent_id)
{
    return $this->home_model->checkChildExists($parent_id);
} 
In view
$checkChildExists = $this->method_call->checkChildExists($parent_id);

Thursday, January 10, 2013

How to Add and Upload an Image using CKEditor

How to Upload Image using CKEditor OR How to enable image upload option in Ckeditor

Step 1 : Download CKEditor Version 4.0.1 standard

Step 2 : open ckeditor\config.js

Step 3 : Add this line  after Line No : 27
                   config.filebrowserUploadUrl = '../ckupload.php';

Step 4 : Create ckupload.php file  ( ckeditor\ckupload.php )
           
             ckupload.php file code            
           
<?php
$url = 'images/uploads/'.time()."_".$_FILES['upload']['name'];
    if (($_FILES['upload'] == "none") OR (empty($_FILES['upload']['name'])) )
    {
       $message = "No file uploaded.";
    }
    else if ($_FILES['upload']["size"] == 0)
    {
       $message = "The file is of zero length.";
    }
    else if (($_FILES['upload']["type"] != "image/pjpeg") AND ($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/png"))
    {
       $message = "The image must be in either JPG or PNG format. Please upload a JPG or PNG instead.";
    }
    else if (!is_uploaded_file($_FILES['upload']["tmp_name"]))
    {
       $message = "You may be attempting to hack our server. We're on to you; expect a knock on the door sometime soon.";
    }
    else {
      $message = "";
      $move = @ move_uploaded_file($_FILES['upload']['tmp_name'], $url);
      if(!$move)
      {
         $message = "Error moving uploaded file. Check the script is granted Read/Write/Modify permissions.";
      }
      $url = "../" . $url;
    }

$funcNum = $_GET['CKEditorFuncNum'] ;
echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>";
?>


Step 5 : Create Folder in ckeditor\
                       Folder Name :-  images\uploads

Step 6 : Run your page in php 
                 
               EX: (http://localhost/ckeditor/samples/replacebyclass.php) 
                                            OR
               EX: (http://localhost/ckeditor/samples/replacebyclass.html) 

 

Tuesday, January 8, 2013

Products Display without Category id in Magento

Products Display without Category id in Magento

require_once ("D:\wamp\www\examples\magento\app\Mage.php");
umask(0);
Mage::app("default");
   
 //////////////  ALL PRODUCTS DISPLAY WITHOUT CATEGORY ID /////////////
    $collection= Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSort('entity_id', 'asc')
                        ->addAttributeToSelect('*')
                        ->setPage(0, 3);// LIMIT BY ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<table width="100%" border="1">
            <tr>
                <th>Product ID</th>
                <th>Product Name</th>
                <th>SKU</th>
                <th>Price</th>              
                <th>Thumbnail</th>
                <th>Small</th>
                <th>Big</th>
            </tr>
<?php
    foreach ($collection as $product)
    {
        ?>
        <tr>
            <td><?php echo $product->getId();?></td>
            <td><?php echo $product->getName();?></td>
            <td><?php echo $product->getSku();?></td>
            <td><?php echo $product->getPrice();?></td>           
            <td>
                <a href="<?php echo $product->getProductUrl();?>" target="_blank"><img src="<?php echo $product->getThumbnailUrl();?>" /></a>
            </td>
            <td><img src="<?php echo $product->getSmallImageUrl();?>" /></td>
            <td><img src="<?php echo $product->getImageUrl();?>" /></td>
        </tr>
        <?php       
    }
    ?></table>

Category id wise Display a products in Magento

Category id wise Display a products in Magento

require_once ("D:\wamp\www\examples\magento\app\Mage.php");
umask(0);
Mage::app("default");

/////////////// CATEGORY ID WISE DISPALY ALL PRODUCTS ////////////////   
    $cat_id = 5;
    $collection = Mage::getModel('catalog/category')->load($cat_id)
                         ->getProductCollection()
                         ->addAttributeToSelect('*')
                         ->addAttributeToFilter('status', 1)
                         ->addAttributeToFilter('visibility', 4)
                         ->setOrder('name', 'ASC') ;
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
<table width="100%" border="1">
            <tr>
                <th>Product ID</th>
                <th>Product Name</th>
                <th>SKU</th>
                <th>Price</th>              
                <th>Thumbnail</th>
                <th>Small</th>
                <th>Big</th>
            </tr>
<?php
    foreach ($collection as $product)
    {
        ?>
        <tr>
            <td><?php echo $product->getId();?></td>
            <td><?php echo $product->getName();?></td>
            <td><?php echo $product->getSku();?></td>
            <td><?php echo $product->getPrice();?></td>           
            <td>
                <a href="<?php echo $product->getProductUrl();?>" target="_blank"><img src="<?php echo $product->getThumbnailUrl();?>" /></a>
            </td>
            <td><img src="<?php echo $product->getSmallImageUrl();?>" /></td>
            <td><img src="<?php echo $product->getImageUrl();?>" /></td>
        </tr>
        <?php       
    }
    ?></table>

Product details from Product ID in Magento

<?php
require_once ("D:\wamp\www\examples\magento\app\Mage.php");
umask(0);
Mage::app("default");

$productid = 16;   
$model = Mage::getModel('catalog/product'); //getting product model
$_product = $model->load($productid); //getting product object for particular product id
?>
<style>
table {                       
    background-color:#CCC;
}
th{
    color:#FFF;
    background:#666;
    width:150px;
    text-align:left;
}
td{
    background-color:#999
}
h2
{
    text-align:center;
    color:#0FF;
}
</style>
<table width="100%" cellpadding="15" cellspacing="1">
        <tr>
            <td colspan="2"><h2>Magento Single Product Information</h2></td>
        </tr>
        <tr>
            <th>Product Name</th>
            <td><?php echo $_product->getName();?></td>
        </tr>
        <tr>
            <th>Price</th>
            <td><?php echo $_product->getPrice();?></td>
        </tr>
        <tr>
            <th>Special Price</th>
            <td><?php echo $_product->getSpecialPrice();?></td>
        </tr>
        <tr>
            <th>Short Description</th>
            <td><?php echo $_product->getShortDescription();?></td>
        </tr>
        <tr>
            <th>Description</th>
            <td><?php echo $_product->getDescription();?></td>
        </tr>
        <tr>
            <th>Product Url</th>
            <td><?php echo $_product->getProductUrl();?></td>
        </tr>
         <tr>
            <th>Thumb Iamge Url</th>
            <td><?php echo $_product->getThumbnailUrl();?><br /><img src="<?php echo $_product->getThumbnailUrl();?>" /></td>
        </tr>
        <tr>
            <th>Small Image Url</th>
            <td><?php echo $_product->getSmallImageUrl();?><br /><img src="<?php echo $_product->getSmallImageUrl();?>" /></td>
        </tr>
         <tr>
            <th>Image Url</th>
            <td><?php echo $_product->getImageUrl();?><br /><img src="<?php echo $_product->getImageUrl();?>" /></td>
        </tr>       
    </table>


How to get all products information with JSON format in magento?

Step 1 : Create Custom API page in root folder for ex.(mg_api.php)

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$collection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*');
$i = 0;
$product_data = array();
foreach ($collection as $product)
{                       
   $product_data[$i]=array("product_id" => $product->getId(),
                    "name" => $product->getName(),
                    "sku" => $product->getSku(),
                    "price" => $product->getPrice(),
                    "url" => $product->getProductUrl(),
                    "thumb" => $product->getThumbnailUrl(),
                    "small" => $product->getSmallImageUrl(),
                    "big" => $product->getImageUrl()
                    );
    $i++;
}
echo json_encode(array('data' => $product_data));
?>

Step 2 : Fetch data from Custom API page using CURL

  $url = 'http://localhost/examples/magento_161/mg_api.php';

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($ch);
  $info = curl_getinfo($ch);
  curl_close($ch);
  $data = json_decode($result, true);

  echo "<pre>";
  print_r($data);
  echo "</pre>";

Friday, January 4, 2013

Create Dynamic DHTML Menu with PHP and Mysql

Create Dynamic DHTML Menu with PHP and mysql. How to create a dynamic menu from database by using PHP and mySQL database with multiple level.

Download this file  : dynamic_menu_with_php_mysql.zip

Wednesday, January 2, 2013

Download Simple CRUD application in codeigniter with Pagination and Image Upload with Resize

Download Simple CRUD application in CodeIgniter with Pagination and Image Upload with Resize.

Download Zip File : codeIgniter_cms.zip
rathoddhirendra.blogspot.com-Google pagerank and Worth