前の基礎ができたら、次のステップはページを表示することです。
プレビューは次のとおりです: 1 日と 31 日にそれぞれアクティビティがあり、一緒に表示されます
いくつかここで行う必要があります 問題、1 つはデータベース接続です。sysclassclass.db_connect.inc.php
<?php
<span style="color: #008000">/*</span>
<span style="color: #008000"> * 数据库操作(数据库访问,认证等)</span>
<span style="color: #008000"> */</span>
<span style="color: #0000ff">class</span> DB_Connect
{
<span style="color: #008000">/**</span>
<span style="color: #008000"> * Stores a database object</span>
<span style="color: #008000"> *</span>
<span style="color: #008000"> * @var object A database object</span>
<span style="color: #008000"> */</span>
<span style="color: #0000ff">protected</span> $db;
<span style="color: #008000">/**</span>
<span style="color: #008000"> * Checks for a DB object or creates one if one isn't found</span>
<span style="color: #008000"> *</span>
<span style="color: #008000"> * @param object $dbo A database object</span>
<span style="color: #008000"> */</span>
<span style="color: #0000ff">protected</span> <span style="color: #0000ff">function</span> __construct($db = NULL)
{
<span style="color: #0000ff">if</span> (is_object($db)) {
$this->db = $db;
} <span style="color: #0000ff">else</span> {
<span style="color: #008000">// Constants are defined in /sys/config/db-cred.inc.php</span>
$dsn = <span style="color: #006080">"mysql:host="</span> . DB_HOST . <span style="color: #006080">";dbname="</span> . DB_NAME;
try {
$this->db = <span style="color: #0000ff">new</span> PDO($dsn, DB_USER, DB_PASS, <span style="color: #0000ff">array</span>(PDO::MYSQL_ATTR_INIT_COMMAND => <span style="color: #006080">'SET NAMES '</span> . DB_ENCODE));
} catch (Exception $e) {
<span style="color: #008000">// If the DB connection fails, output the error</span>
<span style="color: #0000ff">die</span> ($e->getMessage());
}
}
}
}
?>
DB_USERなどの定義ファイルをプログラムに導入する必要があります: db-cred.inc.php
<?php
<span style="color: #008000">/*</span>
<span style="color: #008000"> * Created on 2012-4-24 by xiongxuebing</span>
<span style="color: #008000"> */</span>
<span style="color: #008000">/*</span>
<span style="color: #008000">* Create an empty array to store constants</span>
<span style="color: #008000">*/</span>
$C = <span style="color: #0000ff">array</span>();
<span style="color: #008000">/*</span>
<span style="color: #008000">* The database host URL</span>
<span style="color: #008000">*/</span>
$C[<span style="color: #006080">'DB_HOST'</span>] = <span style="color: #006080">'localhost'</span>;
<span style="color: #008000">/*</span>
<span style="color: #008000">* The database username</span>
<span style="color: #008000">*/</span>
$C[<span style="color: #006080">'DB_USER'</span>] = <span style="color: #006080">'root'</span>;
<span style="color: #008000">/*</span>
<span style="color: #008000">* The database password</span>
<span style="color: #008000">*/</span>
$C[<span style="color: #006080">'DB_PASS'</span>] = <span style="color: #006080">'root'</span>;
<span style="color: #008000">/*</span>
<span style="color: #008000">* The name of the database to work with</span>
<span style="color: #008000">*/</span>
$C[<span style="color: #006080">'DB_NAME'</span>] = <span style="color: #006080">'php-jquery_example'</span>;
$C[<span style="color: #006080">'DB_ENCODE'</span>] = <span style="color: #006080">'UTF8'</span>;
?>
DB_HOST のような定数は直接定義されておらず、/sys/core/init.inc.php で定義されていることに注意してください。
foreach ($C as $name => $val) {<br> define($name, $val);<br>}
原文件如下的示:
<?php
<span style="color: #008000">/*</span>
<span style="color: #008000"> * Created on 2016-6-19 by luhx</span>
<span style="color: #008000"> */</span>
session_start();
<span style="color: #008000">/*</span>
<span style="color: #008000">* Generate an anti-CSRF token if one doesn't exist</span>
<span style="color: #008000">*/</span>
<span style="color: #0000ff">if</span> (!<span style="color: #0000ff">isset</span>($_SESSION[<span style="color: #006080">'token'</span>])) {
$_SESSION[<span style="color: #006080">'token'</span>] = sha1(uniqid(mt_rand(), TRUE));
}
<span style="color: #008000">/*</span>
<span style="color: #008000">* Include the necessary configuration info</span>
<span style="color: #008000">*/</span>
<span style="color: #0000ff">include_once</span> <span style="color: #006080">'../sys/config/db-cred.inc.php'</span>;
<span style="color: #008000">/*</span>
<span style="color: #008000">* Define constants for configuration info</span>
<span style="color: #008000">*/</span>
<span style="color: #0000ff">foreach</span> ($C <span style="color: #0000ff">as</span> $name => $val) {
define($name, $val);
}
<span style="color: #008000">/*</span>
<span style="color: #008000">* Create a PDO object</span>
<span style="color: #008000">*/</span>
$dsn = <span style="color: #006080">"mysql:host="</span> . DB_HOST . <span style="color: #006080">";dbname="</span> . DB_NAME;
$dbo = <span style="color: #0000ff">new</span> PDO($dsn, DB_USER, DB_PASS);
<span style="color: #008000">/*</span>
<span style="color: #008000">* Define the auto-load function for classes</span>
<span style="color: #008000">*/</span>
<span style="color: #0000ff">function</span> __autoload($<span style="color: #0000ff">class</span>)
{
$filename = <span style="color: #006080">"../sys/class/class."</span> . $<span style="color: #0000ff">class</span> . <span style="color: #006080">".inc.php"</span>;
<span style="color: #0000ff">if</span> (file_exists($filename)) {
<span style="color: #0000ff">include_once</span> $filename;
}
}
?>
接下来需显示日历:index.php
<?php
<span style="color: #008000">/*</span>
<span style="color: #008000"> * Created on 2012-4-24 by xiongxuebing</span>
<span style="color: #008000"> */</span>
<span style="color: #008000">/*</span>
<span style="color: #008000">* 包含必须的文件</span>
<span style="color: #008000">*/</span>
<span style="color: #0000ff">include_once</span> <span style="color: #006080">'../sys/core/init.inc.php'</span>;
<span style="color: #008000">/*</span>
<span style="color: #008000">* 载入日历</span>
<span style="color: #008000">*/</span>
$cal = <span style="color: #0000ff">new</span> Calendar($dbo, <span style="color: #006080">"2010-01-01 12:00:00"</span>);
<span style="color: #008000">/**</span>
<span style="color: #008000"> * 初始化标题和样式文件</span>
<span style="color: #008000"> */</span>
$page_title = <span style="color: #006080">"Events Calendar"</span>;
$css_files = <span style="color: #0000ff">array</span>(<span style="color: #006080">'style.css'</span>);
<span style="color: #0000ff">include_once</span> <span style="color: #006080">'assets/common/header.inc.php'</span>;
?>
<?php
<span style="color: #008000">/*</span>