正确处理页面控制器woopagecontroller.php,当提交表单时是否跳转正确的页面

注册表类文件registry.php

<?php
abstract class woo_base_Registry{
	abstract protected function get($key);
	abstract protected function set($key,$val);
}
class woo_base_RequestRegistry extends woo_base_Registry{
	private $values=array();
	private static $instance;
	private function __construct(){}
	static function instance(){
		if(!isset(self::$instance)){
			self::$instance=new self();
		}
		return self::$instance;
	}
	protected function set($key,$val){
		$this->values[$key]=$val;
	}
	protected function get($key){
		if(isset($this->values[$key])){
			return $this->values[$key];
		}
		return null;
	}
	static function setRequest(woo_controller_Request $request){
		return self::instance()->set('request',$request);
	}
	static function getRequest(){
		return self::instance()->get('request');
	}
}
class woo_base_SessionRegistry extends woo_base_Registry{
	private static $instance;
	private function __construct(){
		session_start();
	}
	static function instance(){
		if(!isset(self::$instance)){
			self::$instance=new self();
		}
		return self::$instance;
	}
	protected function set($key,$val){
		$_SESSION[__CLASS__][$key]=$val;
	}
	protected function get($key){
		if(isset($_SESSION[__CLASS__][$key])){
			return $_SESSION[__CLASS__][$key];
		}
		return null;
	}
	function setComplex(Complex $complex){
		self::instance()->set('complex',$complex);
	}
	function getComplex(){
		return self::instance()->get('complex');
	}
}
class woo_base_ApplicationRegistry extends woo_base_Registry{
	private static $instance;
	protected $freezdir="data";
	protected  $values=array();
	protected $mtimes=array();
	private $compute,$appcontroller,$map;
	private function __construct(){}
	static function instance(){
		if(!isset(self::$instance)){
			self::$instance=new self();
		}
		return self::$instance;
	}
	static function getDsn(){
		return self::instance()->get('dsn');
	}
	static function setDsn($dsn){
		self::instance()->set('dsn',$dsn);
	}
	static function setStatus($status){
		self::instance()->set('command',$status);
	}
	static function getStatus(){
		return self::instance()->get('command');
	}
	static function appController(){
		return self::instance()->getAppcontroller(); 
	}
	static function getAppcontroller(){
		return $this->appcontroller=new woo_controller_AppController();
	}
	static function setControllerMap($map){
		$this->map=$map;
	}
	static function getControllerMap(){
		return $this->map;
	}
	function getCompute(){
		return $this->compute=new applicationRegistry_compute();
	}
	protected function set($key,$val){
		return $this->getCompute()->set($key,$val);
	}
	protected function get($key){
		return $this->getCompute()->get($key);
	}
}
class applicationRegistry_compute extends woo_base_ApplicationRegistry{
	protected function set($key,$val){
		$this->values[$key]=$val;
		$path=$this->freezdir . DIRECTORY_SEPARATOR .$key;
		file_put_contents($path,serialize($val));
		$this->mtimes[$key]=time();
	}
	protected function get($key){
		return $this->getFile($key);
		return $this->getVal($key);
		return null;
	}
	function getFile($key){
		$path=$this->freezdir . DIRECTORY_SEPARATOR .$key;
		if(file_exists($path)){
			clearstatcache();
			$mtime=filemtime($path);
			if(!isset($this->mtimes[$key])){$this->mtimes[$key]=0;}
			if($mtime > $this->mtimes[$key]){
				$this->mtimes[$key]=$mtime;
				$data=file_get_contents($path);
				return ($this->values[$key]=unserialize($data));
			}
		}
	}
	function getVal($key){
		if(isset($this->values[$key])){
			return $this->values[$key];
		}
	}
}
class woo_controller_Request{
	private $properties;
	private $feedback=array();
	private $command=array();
	private $cmd;
	function __construct(){
		$this->init();
		woo_base_RequestRegistry::setRequest($this);
	}
	function init(){
		if(isset($_SERVER['REQUEST_METHOD'])){
			$this->properties=$_REQUEST;
			return;
		}
		foreach($_SERVER['argv'] as $arg){
			if(strpos($arg,'=')){
				list($key,$val)=explode('=',$arg);
				$this->setProperty($key,$val);
			}
		}
	}
	function setProperty($key,$val){
		$this->properties[$key]=$val;
	}
	function getProperty($key){
		if(isset($this->properties[$key])){
			return $this->properties[$key];
		}
	}
	function setLastCommand($key){
		array_push($this->command,$key);
	}
	function getLastCommand(){
		if(count($this->command)>0){
			return end($this->command);
		}
	}
	function setFeedback($msg){
		array_push($this->feedback,$msg);
	}
	function getFeedback(){
		return $this->feedback;
	}
	function getFeedbackString($separator="\n"){
		return implode($separator,$this->feedback);
	}
	function setCommand(woo_command_Command $cmd){
		$this->cmd=$cmd;
	}
}
/**
applicationRegistry_compute::setDsn('8.8.8.8');
echo applicationRegistry_compute::getDsn('dsn');
$controller=new woo_controller_Request();
$controller->setFeedback('这是注册表');
echo $controller->getProperty('a');

print_r(woo_base_RequestRegistry::instance()->getRequest());
**/
?>

第二个文件页面控制器woopagecontroller.php

<?php
require("Registry.php");
require("woodomainvenue.php");
abstract class woo_controller_PageController{
	private $request;
	function __construct(){
		$request=woo_base_RequestRegistry::getRequest();
		if(is_null($request)){$request=new woo_controller_Request();}
		$this->request=$request;
	}
	abstract function process();
	function forward($resource){
		include($resource);
		exit(0);
	}
	function getRequest(){
		return $this->request;
	}
}
class woo_controller_AddVenueController extends woo_controller_PageController{
	function process(){
		try{
			$request=$this->getRequest();
			$name=$request->getProperty('venue_name');
			if(is_null($request->getProperty('submitted'))){
				$request->setFeedback("choose a name for the venue");
				$this->forward("addvenue.php");
			}else if($name==''){
				$request->setFeedback("name is a required field");
				$this->forward("addvenue.php");
			}else{
				$venue=new woo_domain_Venue(null,$name);
				$this->forward("listvenue.html");
				//return $venue;
			}
			
		}catch(Exception $e){
			$this->forward('error.php');
		}
	}
}
$controller=new woo_controller_AddVenueController();
$controller->process();
?>

第三个文件addvenue.php文件,在浏览器中访问addvenue.php,当提交给woopagecontroller.php处理时会正确跳转到指定的文件listvenue.html

<html>
<head>
<title>Add Venue</title>
</head>
<body>
<h1>Add Venue</h1>
<table>
<tr>
</td>

</td>
</tr>
</table>
<form action="woopagecontroller.php" method="get">
	<input type="submit" name="submitted" value="提交"/>
	<input type="text" name="venue_name"/>
</form>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值