ishaq/simple-youtube-embed-manager

轻松将YouTube视频整合到您的网站中

dev-master 2015-08-14 01:13 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:32:19 UTC


README

轻松将YouTube视频嵌入到您的网站中。您只需要插入视频ID、视频标题和描述,视频就会出现在您的网站上。

安装说明

注意:为了使用此模块,您需要安装CForm和CDatabase。

  • 首先,您需要一份[Anax-MVC][1]的副本。
  • 将"app"和"src"文件夹拖放到您的Anax副本中。
  • 在webroot文件夹中创建一个新的frontcontroller,并插入以下行
// Create services and inject into the app. 
$di = new \Anax\DI\CDIFactoryDefault();

$di->setShared('db', function() {
    $db = new \Mos\Database\CDatabaseBasic();
    $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php');
    $db->connect();
    return $db;
});

$di->set('YoutubeController', function() use ($di) {
    $controller = new \Ishaq\Youtube\YoutubeController();
    $controller->setDI($di);
    return $controller;
});

$app = new \Anax\Kernel\CAnax($di);
$di->set('form', '\Mos\HTMLForm\CForm');
$app->session;


// Get navbar
$app->navbar->configure(ANAX_APP_PATH . 'config/navbar_youtube.php');

// Routes
$app->router->add('', function() use ($app) {

    $app->theme->setTitle("Youtube");

    $app->views->add('youtube/page', [
        'content' => "<h1 style='border: 0;'>Welcome to the Youtube Videos database!</h1>",
    ]);

});

$app->router->add('setup', function() use ($app) {

    $app->theme->setTitle("Setup Videos");
 
    $app->db->dropTableIfExists('youtube')->execute();
 
    $app->db->createTable(
        'youtube',
        [
            'id' => ['integer', 'primary key', 'not null', 'auto_increment'],
            'title' => ['varchar(80)','not null'],
            'ytid' => ['varchar(80)','not null'],
            'description' => ['varchar(255)','not null'],
            'created' => ['datetime'],
        ]
    )->execute();


    // insert Two test videos
    $app->db->insert(
        'youtube',
        ['title', 'ytid', 'description','created']
    );
    
    $now = date("Y-m-d h:i:s");
 
    $app->db->execute([
        'Zlatan Ibrahimovic - Craziest Skills Ever - Impossible Goals',
        'ln35qLphK4I',
        'Music : What So Not - Touched _Slumberjack Edit',
        $now
    ]);
 
    $app->db->execute([
        'Avicii - The Nights',
        'UtF6Jej8yb4',
        'The Nights" is a song by Swedish DJ and music producer Avicii.',
        $now
    ]);
    $app->db->execute([
        'Shakira - Waka Waka',
        'pRpeEdMmmQ0',
        '"Waka Waka (This Time for Africa)" (Spanish: "Waka Waka (Esto es África)") is a song by Colombian singer-songwriter Shakira featuring South African band Freshlyground',
        $now
    ]);

    $url = $app->url->create('youtube/videos');

    $app->response->redirect($url);
});

就这样!您可以通过www.yoursite.com/webroot/yourfrontcontroller.php访问YouTube模块

演示

http://www.student.bth.se/~isjc13/phpmvc/kmom05/webroot/youtube.php/youtube/videos [1]:https://github.com/mosbth/Anax-MVC