Home > php教程 > php手册 > php学习,一个简单的Calendar(2) 一个简单的活动页面

php学习,一个简单的Calendar(2) 一个简单的活动页面

WBOY
Release: 2016-06-20 08:42:13
Original
919 people have browsed it

有了前面的基础,后面就是将页面展示出来。

预览图如下:1号和31号分别有活动,会一并显示出来

image

 

这里需要搞定几个问题,一个就是数据库的连接,我们用\sys\class\class.db_connect.inc.php

<?php 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000"> * 数据库操作(数据库访问,认证等)</span>
Copy after login
<span style="color: #008000"> */</span>
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #0000ff">class</span> DB_Connect
Copy after login
{
Copy after login
Copy after login
    <span style="color: #008000">/**</span>
Copy after login
<span style="color: #008000">     * Stores a database object</span>
Copy after login
<span style="color: #008000">     *</span>
Copy after login
<span style="color: #008000">     * @var object A database object</span>
Copy after login
<span style="color: #008000">     */</span>
Copy after login
    <span style="color: #0000ff">protected</span> $db;
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
    <span style="color: #008000">/**</span>
Copy after login
<span style="color: #008000">     * Checks for a DB object or creates one if one isn't found</span>
Copy after login
<span style="color: #008000">     *</span>
Copy after login
<span style="color: #008000">     * @param object $dbo A database object</span>
Copy after login
<span style="color: #008000">     */</span>
Copy after login
    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">function</span> __construct($db = NULL)
Copy after login
    {
Copy after login
        <span style="color: #0000ff">if</span> (is_object($db)) {
Copy after login
            $this->db = $db;
Copy after login
        } <span style="color: #0000ff">else</span> {
Copy after login
            <span style="color: #008000">// Constants are defined in /sys/config/db-cred.inc.php</span>
Copy after login
            $dsn = <span style="color: #006080">"mysql:host="</span> . DB_HOST . <span style="color: #006080">";dbname="</span> . DB_NAME;
Copy after login
            try {
Copy after login
                $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));
Copy after login
            } catch (Exception $e) {
Copy after login
                <span style="color: #008000">// If the DB connection fails, output the error</span>
Copy after login
                <span style="color: #0000ff">die</span> ($e->getMessage());
Copy after login
            }
Copy after login
        }
Copy after login
    }
Copy after login
}
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
?>
Copy after login
Copy after login

程序中需要引入DB_USER等的定义文件:db-cred.inc.php

<?php 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000"> * Created on 2012-4-24 by xiongxuebing</span>
Copy after login
Copy after login
<span style="color: #008000"> */</span>
Copy after login
Copy after login
Copy after login
 <span style="color: #008000">/*</span>
Copy after login
<span style="color: #008000">* Create an empty array to store constants</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
$C = <span style="color: #0000ff">array</span>();
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* The database host URL</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
$C[<span style="color: #006080">'DB_HOST'</span>] = <span style="color: #006080">'localhost'</span>;
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* The database username</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
$C[<span style="color: #006080">'DB_USER'</span>] = <span style="color: #006080">'root'</span>;
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* The database password</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
$C[<span style="color: #006080">'DB_PASS'</span>] = <span style="color: #006080">'root'</span>;
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* The name of the database to work with</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
$C[<span style="color: #006080">'DB_NAME'</span>] = <span style="color: #006080">'php-jquery_example'</span>;
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
$C[<span style="color: #006080">'DB_ENCODE'</span>] = <span style="color: #006080">'UTF8'</span>;
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
?>
Copy after login
Copy after login

 

需要注意的是,类似DB_HOST的常量并没有直接定义,而是通过在/sys/core/init.inc.php中进行定义:

foreach ($C as $name => $val) {<br>    define($name, $val);<br>}
Copy after login
原文件如下的示:
Copy after login
 
Copy after login
<?php 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000"> * Created on 2016-6-19 by luhx</span>
Copy after login
<span style="color: #008000"> */</span>
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
session_start();
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* Generate an anti-CSRF token if one doesn't exist</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #0000ff">if</span> (!<span style="color: #0000ff">isset</span>($_SESSION[<span style="color: #006080">'token'</span>])) {
Copy after login
    $_SESSION[<span style="color: #006080">'token'</span>] = sha1(uniqid(mt_rand(), TRUE));
Copy after login
}
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* Include the necessary configuration info</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
<span style="color: #0000ff">include_once</span> <span style="color: #006080">'../sys/config/db-cred.inc.php'</span>;
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* Define constants for configuration info</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #0000ff">foreach</span> ($C <span style="color: #0000ff">as</span> $name => $val) {
Copy after login
    define($name, $val);
Copy after login
}
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* Create a PDO object</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
$dsn = <span style="color: #006080">"mysql:host="</span> . DB_HOST . <span style="color: #006080">";dbname="</span> . DB_NAME;
Copy after login
$dbo = <span style="color: #0000ff">new</span> PDO($dsn, DB_USER, DB_PASS);
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* Define the auto-load function for classes</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
<span style="color: #0000ff">function</span> __autoload($<span style="color: #0000ff">class</span>)
Copy after login
{
Copy after login
Copy after login
    $filename = <span style="color: #006080">"../sys/class/class."</span> . $<span style="color: #0000ff">class</span> . <span style="color: #006080">".inc.php"</span>;
Copy after login
    <span style="color: #0000ff">if</span> (file_exists($filename)) {
Copy after login
        <span style="color: #0000ff">include_once</span> $filename;
Copy after login
    }
Copy after login
}
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
?>
Copy after login
Copy after login

 

接下来需显示日历:index.php

<?php 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000"> * Created on 2012-4-24 by xiongxuebing</span>
Copy after login
Copy after login
<span style="color: #008000"> */</span>
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* 包含必须的文件</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #0000ff">include_once</span> <span style="color: #006080">'../sys/core/init.inc.php'</span>;
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">* 载入日历</span>
Copy after login
<span style="color: #008000">*/</span>
Copy after login
Copy after login
Copy after login
$cal = <span style="color: #0000ff">new</span> Calendar($dbo, <span style="color: #006080">"2010-01-01 12:00:00"</span>);
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/**</span>
Copy after login
<span style="color: #008000"> * 初始化标题和样式文件</span>
Copy after login
<span style="color: #008000"> */</span>
Copy after login
Copy after login
$page_title = <span style="color: #006080">"Events Calendar"</span>;
Copy after login
$css_files = <span style="color: #0000ff">array</span>(<span style="color: #006080">'style.css'</span>);
Copy after login
<span style="color: #0000ff">include_once</span> <span style="color: #006080">'assets/common/header.inc.php'</span>;
Copy after login
?>
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<?php 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<span style="color: #008000">/*</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template