开发者

How do I call this function in CodeIgniter controller?

开发者 https://www.devze.com 2023-01-01 05:37 出处:网络
I\'ve got this code, but I\'m not sure I make it work: /** * Function: youtube data grabber * * @description :

I've got this code, but I'm not sure I make it work:

/**
 * Function: youtube data grabber
 *
 * @description :
 * @param  $ : video code, url type (embed/url)
 * @return : data array
 * @author : Mamun.
 * @last -modified-by: Mamun.
 */

if (! function_exists('youtube_data_grabber'))
        {

                function youtube_data_grabber($video_code, $link_type = "embed")
                {
                        if ($video_code != '')
                        {
                            if ($link_type == "embed")
                            {
                                $splited_data = explode("=",$video_code);
                                $video_unique_code = substr(strrchr($splited_data[4],"/"),1,-strlen(strrchr($splited_data[4],"&")));

                            }
                            else if ($link_type == "url")
                            {
                                $splited_data = explode("=",$video_code);
                                $video_unique_code = substr($splited_data[1],0,-strlen(strrchr($splited_data[1],"&")));
                            }
                            else
                 开发者_如何学运维           {
                                return;
                            }

                                // set feed URL
                                $feedURL = 'http://gdata.youtube.com/feeds/api/videos/'.$video_unique_code;

                                // read feed into SimpleXML object
                                $sxml = simplexml_load_file($feedURL);

                            return $sxml;
                        }

                }
        } // End Youtube Function

I'm not sure how to activate it is what I'm trying to say. I placed it in the controller and it's within a function for one of my pages. I don't have any syntax errors. I just don't know how to wake it up and make it work. I thought I could just put youtube_data_grabber('http://www.youtube.com/watch?v=LAcrFym10ZI', 'url'); but that didn't work.

I got the code from this blog, and I have the zend functionality working. I tested it earlier and had no errors. I'm just having trouble with this youtube part.

Any ideas?


That code should go in a helper or plugin not in the controller. The first part of the code on that page should be in your controller. The one you pasted is just an alternate version.


Save your code to application/helpers/youtube_helper.php, then in your controller go ahead and call $this->load->helper('youtube').

Only then will your youtube_data_grabber() function be available.

0

精彩评论

暂无评论...
验证码 换一张
取 消