1. gao shuai
  2. myswap

Source

myswap / 1 / code / App / Lib / Action / TestAction.class.php

<?php
Class TestAction extends Action{
	protected $fields = array(
	"swap_id", 
	"user_id", 
	"alias", 
	"content", 
	"_pk"=>"swap_id",
	"_autoinc"=>true
	); 
    public function index()
    {
    	$data=array(
		"alias" => "aaa",
		"swap_id" => "aasssa",
		"content" => "asadasdaa",
		"user_id" => "asadasdaa"
		);
		echo dump($data);
		echo in_array("ss",$this->fields,true);
	    foreach ($data as $key=>$val){
	        if(!in_array($key,$this->fields,true)){
	        	// echo $key;
	            unset($data[$key]);
	        }elseif(C('DB_FIELDTYPE_CHECK') && is_scalar($val)) {
	            // 字段类型检查
	            $fieldType = strtolower($this->fields['_type'][$key]);
	            if(false !== strpos($fieldType,'int')) {
	                $data[$key]   =  intval($val);
	            }elseif(false !== strpos($fieldType,'float') || false !== strpos($fieldType,'double')){
	                $data[$key]   =  floatval($val);
	            }
	        }
	    }
		echo dump($data);
    }
}
?>