機能の一部。これの目的は、教師が自分のスケジュールを更新することです。彼女はこのページにアクセスして変更を行い、それらの変更がメイン ページに反映されて潜在的な生徒に表示されます
これは非常に簡単です...基本的には、データを出力し、わずかに異なるマークアップを使用するだけです。したがって、最初に行う必要があるのは、コンテナーとコンテンツを分割し、ファイルの名前を変更して、次のようにすることです。
で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>