Line 3 describes MVC. After reading the notes summarized by kohana

Source: Internet
Author: User
Tags file info kohana
The first line is bigger. After reading the notes summarized by kohana. None? Phpheader (Content-type: texthtml; charsetutf-8); define (, str_replace (\, ,__ DIR _); set_exception_handler (array (Factory, last_fun )); set a user-defined exception handling function Factory

The first line is bigger. After reading the notes summarized by kohana. None? Php header ('content-type: text/html; charset = UTF-8 '); define ('', str_replace ('\\','/', _ DIR _); // set_exception_handler (array ("Factory", "last_fun"); sets a user-defined exception handling function Factory

The first line is bigger. After reading the notes summarized by kohana. <无>
  $ Val) {$ value [$ key] = self: sanitize ($ val) ;}} elseif (is_string ($ value) {if (self :: $ magic_quotes = TRUE) {$ value = stripslashes ($ value);} if (strpos ($ value, "\ r ")! = FALSE) {$ value = str_replace (array ("\ r \ n", "\ r"), "\ n", $ value );}} return $ value;} public function _ set ($ k, $ v) {$ this-> $ k = $ v;} public function _ call ($ method, $ arg) {echo 'error specify page'; print_r ($ arg); // error specify page} public static function _ callStatic ($ method, $ arg) {print_r ($ arg); // it is unlikely that the static page specified by the error will be written here} public function assign ($ key, $ value) {$ this-> data [$ key] = $ value;} // introduces the public functi template. On display ($ template, $ ext = '.html ') {$ template_path = $ template. $ ext; if (file_exists ($ template_path) {foreach ($ this-> data as $ k = >$ v) {$ this->__ set ($ k, $ v) ;}include $ template_path ;}}// controller class IndexAction extends ProductInterface {public function index () {print_r ($ _ GET ); // $ body = file_get_contents ('php: // input'); // print_r ($ body); // The result is member_id = 1234567 enctype = "multipart/form-data" // Print_r ($ _ POST); // The result is Array ([member_id] => 1234567) // $ model = new Article ('Article '); // $ arr = $ model-> select ('select * FROM article limit 2'); // print_r ($ arr);} public function admin ($ array) {$ model = new Article ('Article'); $ array = array (); $ array ['rec '] = 'admins '; $ array ['pos'] = 'les'; $ array ['content'] = 'hellow world'; echo $ model-> add ($ array );}} /// controller 2 class AdminAction extends Product Interface {public function index ($ array) {echo _ method __. 'method' ;}} class Factory {protected static $ ins = null; protected function _ construct () {ob_start (); // open the buffer static: autoLoad (); register_shutdown_function (array ('factory ', 'last'); // after the program is executed, run} public static function getIns ($ url) {if (self :: $ ins instanceof self) {self ::$ ins-> execute ($ url);} else {self ::$ ins = new self (); self :: $ ins-> execu Te ($ url) ;}} protected function set_router ($ uri) {/* $ uri = 'index/admin'; // $ route_regex = '# ^ (? :(? P [^ /.,;? \ N] ++ )(? :/(? P [^ /.,;? \ N] ++ )(? :/(? P [^ /.,;? \ N] ++ ))?)?)? $ # UD '; // $ route_regex =' # ^ captcha (? :/(? P [^ /.,;? \ N] ++ ))? $ # UD '; $ route_regex =' # ^ (? :(? P
  
   
[^ /.,;? \ N] ++ )(? :/(? P [^ /.,;? \ N] ++ )(? :/(? P
   
    
[^ /.,;? \ N] ++ ))?)?)? $ # UD '; if (! Preg_match ($ route_regex, $ uri, $ matches) {echo 'does not match';} else {print_r ($ matches);} */$ arr = array (); if (strpos ($ uri ,'? ') = False) {$ pathinfo = array (); if (! Empty ($ _ SERVER ['path _ info']) {$ arg = trim ($ _ SERVER ['path _ info'], '/');} else if ($ request_uri = parse_url ($ _ SERVER ['request _ URI '], PHP_URL_PATH) {// valid URL path discovery, set it. $ Arg = trim ($ request_uri, '/');} if (stripos ($ arg ,'/')! = False) {$ pathinfo = explode ('/', $ arg);} $ arr ['ctroloer'] = isset ($ pathinfo [0])? $ Pathinfo [0]: 'index'; array_shift ($ pathinfo); $ arr ['action'] = isset ($ pathinfo [0])? $ Pathinfo [0]: 'index'; array_shift ($ pathinfo); $ num = count ($ pathinfo); for ($ I = 0; $ I <$ num; $ I + = 2) {$ arr ['param'] [$ pathinfo [$ I] = $ pathinfo [$ I + 1];} return $ arr ;} else {$ ln = parse_url ($ uri); parse_str ($ ln ['query'], $ array ); $ arr ['ctroloer'] = $ array ['M']? Strtolower ($ array ['M']): 'index'; $ arr ['action'] = $ array ['C']? Strtolower ($ array ['C']): 'index'; unset ($ array ['M']); unset ($ array ['C']); $ arr ['param'] = $ array; return $ arr ;}} protected function execute ($ url) {$ arr = self :: $ ins-> set_router ($ url); $ _ GET = isset ($ arr ['param'])? $ Arr ['param']: array (); $ ProductType = ucfirst ($ arr ['ctroloer']). 'action'; if (class_exists ($ ProductType) {$ p = new $ ProductType (); $ p-> $ arr ['action'] ($ arr );} else {throw new Exception ("Error Processing Request", 1) ;}} public static function last () // echo 'script executed successfully '. PHP_EOL; {$ info = ob_get_contents (); // obtain the buffer content and assign it to $ info folder file=fopen(1__server}'document_root').directory_separator.'indexs.html', 'W'); // open the file and specify the cache directory fwrite ($ file, $ info); // write the information to info.txt fclose ($ file ); // close the file info.txt // ob_end_clean (); ob_end_flush (); flush ();} static public function loadFile ($ className) {$ dir = array (); $ dir [0] =. '/application/'; // specify multiple directories $ dir [1] =. '/module/'; $ file_arr = self: find_file ($ dir, $ className); foreach ($ file_arr as $ value) {if (is_file ($ value )) {return include_once $ value;} else {throw new \ Exceptio N ('couldn't find '. $ className. 'class') ;}} public static function find_file ($ paths = array (), $ name) {$ name = ucfirst ($ name ). '. php '; $ found = array (); foreach ($ paths as $ dir) {if (is_file ($ dir. $ name) {$ found [] = $ dir. $ name ;}return $ found;} // register the automatic loader static public function autoLoad () {spl_autoload_register (array (_ CLASS __, 'loadfile '));} // register the automatic loader 2 // register multiple automatic loading functions as needed static public function autoLoad2 () {sp L_autoload_register (array (_ CLASS __, 'loadfile2');} abstract class DB {public $ db = NULL; public $ table = NULL; public $ config = array ('dsn '=> 'mysql: dbname = test; host = 127.0.0.1', 'user' => 'root ', 'Password' => 'root', 'charset' => 'utf8', 'persistent' => false // persistent link); public $ options = array (PDO :: MYSQL_ATTR_INIT_COMMAND => "set names",); public function _ construct ($ table) {$ this-> table = $ table; $ this-> op Tions [PDO: MYSQL_ATTR_INIT_COMMAND]. = $ this-> config ['charset']; if ($ this-> config ['persistent']) {$ this-> options [PDO :: ATTR_PERSISTENT] = true;} try {// persistent connection. If necessary, set array (PDO: ATTR_PERSISTENT => true) as the fourth parameter $ this-> db = $ pdo = new \ PDO ($ this-> config ['dsn '], $ this-> config ['user'], $ this-> config ['Password'], $ this-> options); // $ dbh-> setAttribute (PDO: ATTR_ERRMODE, PDO: ERRMODE_SILENT ); // No error is displayed $ pdo-> setA Ttribute (PDO: ATTR_ERRMODE, PDO: ERRMODE_WARNING); // displays a warning error and continues to run $ this-> db-> setAttribute (PDO: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION); // generates a fatal error, PDOException // $ this-> db-> exec ('set names utf8');} catch (\ Exception $ e) {throw new \ Exception ($ e-> getMessage () ;}} public function query ($ SQL) {return $ re = $ this-> db-> query ($ SQL);} public function select ($ SQL) /* query */{$ re = $ this-> query ($ SQL); return $ Re-> fetchAll ();} public function add ($ arr = array () {/* add */$ SQL = 'insert '. $ this-> table. '('. implode (',', array_keys ($ arr )). ')'; $ SQL. = "values ('"; $ SQL. = implode ("','", array_values ($ arr); $ SQL. = "')"; $ stmt = $ this-> db-> prepare ($ SQL); $ stmt-> execute ($ arr ); echo $ this-> db-> lastinsertid ();} public function update ($ arr, $ where = 'where 1 limit 1 ') {/* modify * // $ SQL = "UPDATE 'user 'Set' password' =: password WHERE 'user _ id' =: userId "; $ SQL = 'update '. $ this-> table. 'set'; foreach ($ arr as $ k => $ v) {$ SQL. = $ k. "= '". $ v. "'," ;}$ SQL = rtrim ($ SQL,', '); $ SQL. = $ where; $ stmt = $ this-> db-> prepare ($ SQL); $ stmt-> execute ($ arr); return $ stmt-> rowCount ();} public function delete ($ SQL) {/* delete */$ stmt = $ this-> db-> prepare ($ SQL); $ stmt-> execute (); return $ stmt-> rowCount ();}}//// One Class of each table can inherit the DB class ..... Class Article extends DB {}?> Script var x = 1, y = z = 0; function add (n) {n = n + 1;} y = add (x); function add (n) {n = n + 3;} z = add (x); script
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.