php - Calling other function in the same controller? -


i'm using laravel. here class i'm working on:

<?php  class instagramcontroller extends basecontroller {  /* |-------------------------------------------------------------------------- | default home controller |-------------------------------------------------------------------------- | | may wish use controllers instead of, or in addition to, closure | based routes. that's great! here example controller method | started. route controller, add route: | |   route::get('/', 'homecontroller@showwelcome'); | */  public function read($q) {     $client_id = 'ea7bee895ef34ed08eacad639f515897';      $uri = 'https://api.instagram.com/v1/tags/'.$q.'/media/recent?client_id='.$client_id;     return sendrequest($uri); }  public function sendrequest($uri){     $curl = curl_init($uri);     curl_setopt($curl, curlopt_returntransfer, true);     curl_setopt($curl, curlopt_ssl_verifypeer, 0);     curl_setopt($curl, curlopt_ssl_verifyhost, 0);     $response = curl_exec($curl);     curl_close($curl);     return $response; }  } 

the line:

return sendrequest($uri); 

renders error: call undefined function sendrequest()

i'm assuming it's because i'm referencing function in wrong manner, can't find explanations how it.

try:

return $this->sendrequest($uri); 

since php not pure object-orieneted language, interprets sendrequest() attempt invoke globally defined function (just nl2br() example), since function part of class ('instagramcontroller'), need use $this point interpreter in right direction.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -