功能的一部分。这样做的目的是让老师更新她的日程安排。她进入此页面进行更改,这些更改反映在主页中,供潜在学生查看
这很简单......基本上你只需要输出数据,并使用稍微不同的标记。因此,您需要做的第一件事是拆分容器和内容,然后重命名文件,以便您可能拥有:
在scheduleAdmin.php
:
<?php include(__DIR__ . '/functions.php'); // include path/to/this/files/folder/functions.php ?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<!-- your html -->
<?php // use the special include function to include the partial for the table ?>
<?php include_partial('_scheduleTable.php', array('mode' => 'admin')); ?>
<!-- the rest of your html -->
</body>
</html>
然后在schedule.php
:
<?php include(__DIR__ . '/functions.php'); // include /path/to/this/files/folder/functions.php ?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<!-- your html -->
<?php // use the special include function to include the partial for the table ?>
<?php include_partial('_scheduleTable.php', array('mode' => 'admin')); ?>
<!-- the rest of your html -->
</body>
</html>
现在我们需要创建include_partial
函数,它将采用“部分”(一个 html 片段)的名称和在该“部分”中可用的命名变量数组:
// functions.php
/**
* Directly renders a partial to the screen
*
* @param string $file the filesystem path to the partial
* @param array $vars variables that should be available to the partial
*/
function include_partial($file, $vars = array()) {
// let get_partial do all the work - this is just a shortcut to
// render it immediately
echo get_partial($file, $vars);
}
/**
* Get the contents of a partial as a string
*
* @param string $file the filesystem path to the partial
* @param array $vars variables that should be available to the partial
* @return string
*/
function get_partial($file, $vars = array()) {
// open a buffer
ob_start();
// import the array items to local variables
// ie 'someKey => 'someValue' in the array can be accessed as $someKey
extract($vars);
// include the partial file
include($file);
// get the contents of the buffer and clean it out
// then return that
return ob_get_clean();
}
所以现在我们有了这个集合,我们只需要创建部分文件_scheduleTable.php
:
<?php $classnname = isset($mode) && $mode == 'admin' ? 'the_css_class_for_admin' : 'the_other_css_class'; ?>
<table id="schedule">
<tr class="<?php echo $classname ?>" >
<!-- your td's and what not - jsut needed something to show you how to echo the classname -->
</tr>
</table>