-2

php で解決しようとしている問題がありますが、php プログラミングに関しては全くの初心者です。問題は、jquery で html テーブルを変更していて、次にやりたいことはこれを交換することです。別の html ファイル内の別の正確なテーブル (一部のセルのクラスを除く) を持つテーブル

最初のファイルの名前が scheduleAdmin.html で、もう一方のファイル (同じディレクトリにある) に "転送" したいテーブルがあるとします。両方のファイルに、id='schedule' を持つこのテーブルがあります。

PHP を使えばこれは簡単な作業だと確信していますが、実際にはあまり進歩していません。

どんな助けでも大歓迎です

4

2 に答える 2

0

多分これはうまくいくでしょう。

最初のファイルで:

<?php ob_start(); ?>

    <table id="schedule">
    ...

<?php ob_end_flush();?>

<?php 
    $contents = ob_get_contents();
    file_put_contents('schedule.html',$contents);
?>
于 2013-02-27T03:27:07.730 に答える
0

機能の一部。これの目的は、教師が自分のスケジュールを更新することです。彼女はこのページにアクセスして変更を行い、それらの変更がメイン ページに反映されて潜在的な生徒に表示されます

これは非常に簡単です...基本的には、データを出力し、わずかに異なるマークアップを使用するだけです。したがって、最初に行う必要があるのは、コンテナーとコンテンツを分割し、ファイルの名前を変更して、次のようにすることです。

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>
于 2013-02-27T03:20:45.357 に答える