Skip to main content
deleted 125 characters in body; edited tags; edited title
Source Link
sv3n
  • 11.7k
  • 7
  • 41
  • 73

Use How to get an array from curl in custom module Magento ver 1.9.xresponse

Use curl in custom module Magento ver 1.9.x

In /var/www/html/magento193/app/design/frontend/base/default/template/reviewrating/rightsidebar.phtml

$url = "http://mywebsite.com/api/extentionReviews?key=s4o3mbe8key9";
 
$getJson = $this->getDataFromApi( $url );
 
$ApiData = Mage::helper('core')->jsonDecode( $getJson );

print_r( $getJson );

In /var/www/html/magento193/app/code/local/Custommodule/ReviewRating/Block/Rightsidebar.php

 public function getDataFromApi( $url )
    {
        
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            $data = curl_exec($ch);
            $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            return ($httpcode>=200 && $httpcode<300) ? $data : false;
 
  }

In /var/www/html/magento193/app/design/frontend/base/default/layout/reviewrating.xml

 <reference name="right">
        <block type="reviewrating/rightsidebar" name="reviewrating_rightsidebar" beofre="-"  template="reviewrating/rightsidebar.phtml" />
  </reference>  

Output : I am still getting data in json format. i want it to be in array.

{   "success":true,
    "error":false,
    "error_code":"",
    "message":"Successfully listed."
    ..........  
}

Use curl in custom module Magento ver 1.9.x

Use curl in custom module Magento ver 1.9.x

In /var/www/html/magento193/app/design/frontend/base/default/template/reviewrating/rightsidebar.phtml

$url = "http://mywebsite.com/api/extentionReviews?key=s4o3mbe8key9";
 
$getJson = $this->getDataFromApi( $url );
 
$ApiData = Mage::helper('core')->jsonDecode( $getJson );

print_r( $getJson );

In /var/www/html/magento193/app/code/local/Custommodule/ReviewRating/Block/Rightsidebar.php

 public function getDataFromApi( $url )
    {
        
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            $data = curl_exec($ch);
            $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            return ($httpcode>=200 && $httpcode<300) ? $data : false;
 
  }

In /var/www/html/magento193/app/design/frontend/base/default/layout/reviewrating.xml

 <reference name="right">
        <block type="reviewrating/rightsidebar" name="reviewrating_rightsidebar" beofre="-"  template="reviewrating/rightsidebar.phtml" />
  </reference>  

Output : I am still getting data in json format. i want it to be in array.

{   "success":true,
    "error":false,
    "error_code":"",
    "message":"Successfully listed."
    ..........  
}

How to get an array from curl response

Use curl in custom module Magento ver 1.9.x

In /var/www/html/magento193/app/design/frontend/base/default/template/reviewrating/rightsidebar.phtml

$url = "http://mywebsite.com/api/extentionReviews?key=s4o3mbe8key9";
$getJson = $this->getDataFromApi( $url );
$ApiData = Mage::helper('core')->jsonDecode( $getJson );

print_r( $getJson );

In /var/www/html/magento193/app/code/local/Custommodule/ReviewRating/Block/Rightsidebar.php

public function getDataFromApi( $url )
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    $data = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return ($httpcode>=200 && $httpcode<300) ? $data : false;
}

In /var/www/html/magento193/app/design/frontend/base/default/layout/reviewrating.xml

<reference name="right">
    <block type="reviewrating/rightsidebar" name="reviewrating_rightsidebar" beofre="-"  template="reviewrating/rightsidebar.phtml" />
</reference>

Output : I am still getting data in json format. i want it to be in array.

{   "success":true,
    "error":false,
    "error_code":"",
    "message":"Successfully listed."
    ..........  
}

Use cUrlcurl in custom module MagnetoMagento ver 1.9.x

Use cUrlcurl in custom module MagnetoMagento ver 1.9.x

In /var/www/html/magento193/app/design/frontend/base/default/template/reviewrating/rightsidebar.phtml

$url = "http://mywebsite.com/api/extentionReviews?key=s4o3mbe8key9";

$getJson = $this->getDataFromApi( $url );

$ApiData = Mage::helper('core')->jsonDecode( $getJson );

print_r( $getJson );

In /var/www/html/magento193/app/code/local/Custommodule/ReviewRating/Block/Rightsidebar.php

 public function getDataFromApi( $url )
    {
        
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            $data = curl_exec($ch);
            $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            return ($httpcode>=200 && $httpcode<300) ? $data : false;

  }

In /var/www/html/magento193/app/design/frontend/base/default/layout/reviewrating.xml

 <reference name="right">
        <block type="reviewrating/rightsidebar" name="reviewrating_rightsidebar" beofre="-"  template="reviewrating/rightsidebar.phtml" />
  </reference>  

Output : I am still getting data in json format. i want it to be in array.

{   "success":true,
    "error":false,
    "error_code":"",
    "message":"Successfully listed."
    ..........  
}

Use cUrl in custom module Magneto ver 1.9.x

Use cUrl in custom module Magneto ver 1.9.x

In /var/www/html/magento193/app/design/frontend/base/default/template/reviewrating/rightsidebar.phtml

$url = "http://mywebsite.com/api/extentionReviews?key=s4o3mbe8key9";

$getJson = $this->getDataFromApi( $url );

$ApiData = Mage::helper('core')->jsonDecode( $getJson );

print_r( $getJson );

In /var/www/html/magento193/app/code/local/Custommodule/ReviewRating/Block/Rightsidebar.php

 public function getDataFromApi( $url )
    {
        
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            $data = curl_exec($ch);
            $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            return ($httpcode>=200 && $httpcode<300) ? $data : false;

  }

In /var/www/html/magento193/app/design/frontend/base/default/layout/reviewrating.xml

 <reference name="right">
        <block type="reviewrating/rightsidebar" name="reviewrating_rightsidebar" beofre="-"  template="reviewrating/rightsidebar.phtml" />
  </reference>  

Output : I am still getting data in json format. i want it to be in array.

{   "success":true,
    "error":false,
    "error_code":"",
    "message":"Successfully listed."
    ..........  
}

Use curl in custom module Magento ver 1.9.x

Use curl in custom module Magento ver 1.9.x

In /var/www/html/magento193/app/design/frontend/base/default/template/reviewrating/rightsidebar.phtml

$url = "http://mywebsite.com/api/extentionReviews?key=s4o3mbe8key9";

$getJson = $this->getDataFromApi( $url );

$ApiData = Mage::helper('core')->jsonDecode( $getJson );

print_r( $getJson );

In /var/www/html/magento193/app/code/local/Custommodule/ReviewRating/Block/Rightsidebar.php

 public function getDataFromApi( $url )
    {
        
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            $data = curl_exec($ch);
            $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            return ($httpcode>=200 && $httpcode<300) ? $data : false;

  }

In /var/www/html/magento193/app/design/frontend/base/default/layout/reviewrating.xml

 <reference name="right">
        <block type="reviewrating/rightsidebar" name="reviewrating_rightsidebar" beofre="-"  template="reviewrating/rightsidebar.phtml" />
  </reference>  

Output : I am still getting data in json format. i want it to be in array.

{   "success":true,
    "error":false,
    "error_code":"",
    "message":"Successfully listed."
    ..........  
}
Source Link
inrsaurabh
  • 1.7k
  • 3
  • 27
  • 54

Use cUrl in custom module Magneto ver 1.9.x

Use cUrl in custom module Magneto ver 1.9.x

In /var/www/html/magento193/app/design/frontend/base/default/template/reviewrating/rightsidebar.phtml

$url = "http://mywebsite.com/api/extentionReviews?key=s4o3mbe8key9";

$getJson = $this->getDataFromApi( $url );

$ApiData = Mage::helper('core')->jsonDecode( $getJson );

print_r( $getJson );

In /var/www/html/magento193/app/code/local/Custommodule/ReviewRating/Block/Rightsidebar.php

 public function getDataFromApi( $url )
    {
        
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            $data = curl_exec($ch);
            $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            return ($httpcode>=200 && $httpcode<300) ? $data : false;

  }

In /var/www/html/magento193/app/design/frontend/base/default/layout/reviewrating.xml

 <reference name="right">
        <block type="reviewrating/rightsidebar" name="reviewrating_rightsidebar" beofre="-"  template="reviewrating/rightsidebar.phtml" />
  </reference>  

Output : I am still getting data in json format. i want it to be in array.

{   "success":true,
    "error":false,
    "error_code":"",
    "message":"Successfully listed."
    ..........  
}