我有以下 XML 文件:
<?xml version="1.0" ?>
<Videos>
<video>
<Title>Video Title</Title>
<SubHeading>SubTitle</SubHeading>
<url>UIIArHNaKtE</url>
<image>image.png</image>
<category>3</category>
<latest>0</latest>
</video>
<video>
<Title>Video Title</Title>
<SubHeading>SubTitle</SubHeading>
<url>UIIArHNaKtE</url>
<image>image.png</image>
<category>3</category>
<latest>0</latest>
</video>
<video>
<Title>Video Title</Title>
<SubHeading>SubTitle</SubHeading>
<url>UIIArHNaKtE</url>
<image>image.png</image>
<category>3</category>
<latest>0</latest>
</video>
</Videos>
使用模型文件:
<?php
class xmlmodel extends CI_Model{
public function catalog(){
$doc = new DOMDocument();
$path = '../application/libraries/VideoData.xml';
$doc->load($path);//xml file loading here
$data = $doc->getElementsByTagName('video');
return $data;
}
}
控制器:
<?php
class SixD extends CI_Controller {
public function index($sixD = 'latestadditions') {
if (!file_exists('../application/views/page/' . $sixD . '.php')) {
// Whoops, we don't have a page for that!
show_404();
}
$this->load->model('xmlmodel');
$data['category_catalog_entity'] = $this->xmlmodel->catalog();
$this->lang->load('common/menu.php');
$this->lang->load('common/headings.php');
$this->lang->load('common/links.php');
$this->lang->load('common/footer.php');
$this->lang->load('page/' . $sixD . '.php');
$this->load->view('templates/common/header');
$this->load->view('page/' . $sixD, $data);
$this->load->view('templates/common/footer');
}
}
并查看:
<div class="container">
<h1 class="pageheading">
<?php echo lang('heading_pageheading'); ?>
</h1>
<hr class="heading" />
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-8 col-lg-9">
<?php foreach($category_catalog_entity as $result){ ?>
<div class="row videopane software">
<div class="col-sm-7 col-sm-push-5">
<h3 class="pageheading"><?php echo anchor('http://youtu.be/' . $result->getElementsByTagName('url')->item(0)->nodeValue, $result->getElementsByTagName('Title')->item(0)->nodeValue . '<br /><small>' . $result->getElementsByTagName( "SubHeading" )->item(0)->nodeValue . '</small>', array('class' => 'fancybox-media'));?></h3>
</div>
<div class="col-sm-5 col-sm-pull-7 text-center">
<?php echo anchor('http://youtu.be/' . $result->getElementsByTagName('url')->item(0)->nodeValue . '?autoplay=1', img("Thumbnails/" . $result->getElementsByTagName('image')->item(0)->nodeValue, $result->getElementsByTagName('Title')->item(0)->nodeValue, $result->getElementsByTagName('Title')->item(0)->nodeValue, "img-responsive img-thumbnail"), array('class' => 'fancybox-media')); ?>
</div>
</div>
<?php }
} ?>
</div>
<div class="col-sm-4 col-lg-3 software">
<?php $this->load->view('modules/menu'); ?>
</div>
</div>
</div>
</div>
</div>
这一切都有效,但是我希望定义在哪个页面上显示什么视频,所以我有 2 个标签:
<category>3</category>
<latest>1</latest>
我想要做的是让所有类别为 3 的视频显示在该页面上,并忽略任何其他类别编号。最新标签用于新视频,因此这将是 1 表示活动或 0 表示不显示。
我应该指出每个页面都有一个单独的视图页面,但基本上使用相同的格式。没有数据库,因此我使用 XML 来控制它,如果有人能给我一些指示,那将非常有用。