Zend framework Youtube class on Codeigniter with jquery

Download

This does not contain Codeigniter or Zend framework. If you need them please download it from here.

Introduction

The previous post “Zend Framework on Codeigniter: Youtube” involved three steps to see a video. And it did not have any style.

Goals

I will reduce it to two steps, add a minimum styling and use jquery tools scrollable.
zend_youtube_2_1


The default videos in a scrollabe screen will be three.

Resources

  1. Jquery Tools Scrollable: I am using a vertical scrollabe this time.
  2. Zend Framework Youtube class
  3. Codeigniter

Config

system/application/config/autoload.php

$autoload['helper'] = array('zend_framework', 'url');

Autoload the zend_framework and url.

system/application/config/config.php

$config['base_url']	="http://127.0.0.1/ci_zend_youtube/";

Add your base url here.

Controller

system/application/controllers/yt_scroll.php

<?php
class Yt_scroll extends Controller{
    protected $_youTube;

function __construct() {
    parent::Controller();
    Zend_Loader::loadClass('Zend_Gdata_YouTube');

    $this->_youTube = new Zend_Gdata_YouTube;

    }

function index(){

    // Gets playlists
    $data['playlistfeed']= $this->_youTube->getPlaylistListFeed('NationalGeographic');
    $this->load->view ('youtube_view3',$data);
    }

public function listAction(){
    // Gets playlist videos

    $playlistId = $this->uri->segment(4);
    $query = $this->_youTube->newVideoQuery(
    'http://gdata.youtube.com/feeds/playlists/' . $playlistId);
    $data['videoFeed']= $this->_youTube->getVideoFeed($query);
    $this->load->view('listaction2_view', $data);
    }

}

Contructor

A variable $_youTube is created with protected.
Constructor function loads Zend_Gdata_YouTube with Zend_Loader.
And a new object is created.

Index () function

PlaylistListFeed of National Geographic is stored in playlistfeed and this will be loaded in youtube_view3.

listAction () function

The fourth segment of uri will be used for $playlistId.
Query is stored to $query and videofeed will be in

View

system/application/views/youtube_view3.php

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Video lists</title>
 <link rel="stylesheet" type="text/css" href="<?=base_url();?>css/default.css" />
 <script src="http://cdn.jquerytools.org/1.1.2/full/jquery.tools.min.js"></script>

</head>
<body>
    <div id="wrapper">
<h1>National Geographic Videos on Youtube</h1>
<div>
<?php foreach ($playlistfeed as $playlistEntry): ?>
<?php $id = substr(strrchr(
$playlistEntry->getPlaylistVideoFeedUrl(), '/'
), 1); ?>
<h3>
<a href="yt_scroll/listAction/id/<?php echo $id; ?>/">
<?php echo $playlistEntry->title->text; ?>
</a>
</h3>
<div class="pane">

<p><?php echo $playlistEntry->description->text; ?></p>
</div>
<?php endforeach; ?>
</div>
</div>
</body>
</html>

Conclusion

You can add a form to submit the video subject like I did for Flickr. You may want to add this to your side column. Pagenation can be added to this.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>