Home > php教程 > php手册 > 用Php模拟asp.net的页面模型

用Php模拟asp.net的页面模型

WBOY
Release: 2016-06-21 09:00:03
Original
1076 people have browsed it

用php模拟asp.net是不大可能的,特别是对于php这样的对面向对象支持不完整的动态语言来讲,更是很大的困难.在这些说模拟是说可以由这个例子来理解asp.net的运行机制(又说深了,他仅仅是一个模以而以) .代码很简单,无需细说,本测试在win2000,iis5,php 4.4.0上运行通过

page.php

/*********************************************
*Sinoprise Function Classes
*CopyRight(c):2006 Sinoprise Technology Lab
*
*Unit Name: page.php
*func:
*Crate:Shuguang Yin 2006-07-15
*********************************************/
 class SFC_Page
 {
     
     //环境变量
     /*var $Server; 
       var $Session;
       var $QueryString;
       var $Post;
       var $Cookie;
       var $Files;
       var $Env;*/
 
  //页面控制属性
  var $EnableViewState;
 
  //页面属性
  var $CharSet;//页面字符集
  var $PageTitle;//页面的标题
  var $PageStyle;//页面的风格
 
  function SFC_Page()
  {
        
   /*if (strcmp(substr(PHP_VERSION,0,1),4)>=0){

    $Server = $_SERVER; 
    $Session = $_SESSION;
    $QueryString = $_GET;
    $Post = $_POST;
    $Cookie = $_COOKIE;
    $Files = $_FILES;
    $Env = $_ENV;


   }else{


    global $HTTP_SERVER_VARS,$HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_COOKIE_VARS,$HTTP_POST_FILES ;
    global $HTTP_ENV_VARS,$HTTP_SESSION_VARS;
    $Server = $HTTP_SERVER_VARS; 
    $Session = $HTTP_SESSION_VARS;
    $QueryString = $HTTP_GET_VARS;
    $Post = $HTTP_POST_VARS;
    $Cookie = $HTTP_COOKIE_VARS;
    $Files = $HTTP_POST_FILES;
    $Env = $HTTP_ENV_VARS; 

   }*/

   $this->EnableViewState = false; 

  }
  //发生在服务器状态还原之前
  function PageInit()
  {
  }

  //发生在服务器状态还原之后,但在服务器端事件之前
  function PageLoad()
  {
  }

  //发生在激发服务器端事件之后,但在生成任何东西之前
  function PagePreRender()
  {
  }

  //发生在生成页面之时
  function PageRender()
  {
  }

  //发生在网页生成完成之后
  function PageUnLoad()
  {
  }

  //显示输出
  function Display()
  {
   $this->PageInit();
   if ($this->EnableViewState){
                       $this->DeCodeViewState();
   }
   $this->PageLoad();
   $this->PagePreRender();
   echo "

".$this->PageTitle."";
   echo "";
   echo "PageStyle.">";
   echo "
";
   $this->PageRender();
   if ($this->EnableViewState){
                    $this->EnCodeViewState();
   }
   echo "
";     
   $this->PageUnLoad();

  }
 
  //判断是第一次打开还是post
  function IsPostBack()
  {
  
  }
  //对ViewState进行编码
  function EnCodeViewState()
  {
                     echo "                    echo "Value=\"".base64_encode(serialize($this))."\"";
                     echo ">";
  }
  //对ViewState进行解码
  function DeCodeViewState()
  {
               if (isset($_POST['SFC_ViewState'])){
                                $this = unserialize(base64_decode($_POST['SFC_ViewState']));
                 }
  }
 }
?>

页面文件,php.php


 require_once('page.php');
 
 class PhpTest extends SFC_Page
 {
  var $conut;
 
  function PhpTest()
  {
 
  }
  //发生在服务器状态还原之前
  function PageInit()
  {
  }
 
  //发生在服务器状态还原之后,但在服务器端事件之前
  function PageLoad()
  {
  }
 
  //发生在激发服务器端事件之后,但在生成任何东西之前
  function PagePreRender()
  {
  }
 
  //发生在生成页面之时
  function PageRender()
  {
            echo ++$this->conut;  
            //echo serialize($this);
             echo "
";
             echo "";
  }
 
  //发生在网页生成完成之后
  function PageUnLoad()
  {
  } 
 }
 
 $cls = new PhpTest();
 $cls->CharSet="gb2312";
 $cls->PageTitle="页面的标题";
 $cls->EnableViewState=true;
 $cls->Display();
?>



Related labels:
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