• TP框架2


    ——————————

    <?php
    namespace HomeController;
    use ThinkController;
    class IndexController extends Controller {
        public function index(){
            echo"hello world!";
        }
    }
    

     

     用浏览器打开index方法:http://localhost/tp/index.php

    打开

    所以以后在做东西要通过浏览器输入地址查看效果

    新建控制类

    在controller文件下新建  例如:LoginController.class.php //每个单词首字母大写

    <?php
    namespace HomeController;
    use ThinkController;
    class LoginController extends Controller{
        public function login(){
            echo"登录页面!";
        }
    }
    

    地址:http://localhost/tp/index.php/Home/Login/login

    显示效果

    新建模板

    ——————

    在view下新建一个文件夹  ,文件夹名和上面方法名相对应,然后在文件下新建一个和方法名相同的html文件

    在控制类中显示模板的方法

    <?php
    namespace HomeController;
    use ThinkController;
    class LoginController extends Controller{
        public function login(){
            //显示模板
            $this->show();
        }
    }
    

     地址:http://localhost/tp/index.php/Home/Login/login

    显示效果:

    往模板扔变量

    ——打开——

    login.html代码

    <div>登录页面</div>
    <div>{$ceshi}</div>
    

    LoginController.class.php代码

    <?php
    namespace HomeController;
    use ThinkController;
    class LoginController extends Controller{
        public function login(){
            //向TP里面注册变量
            $this->assign("ceshi","张三");
            //显示模板
            $this->show();
        }
    }
    

    从前端往后端传数据

    login.html

    <html>
    <head>
    </head>
    <body>
    <div>我是登录的界面</div>
    <div>{$ceshi}</div>
    
    <form action="__CONTROLLER__/chuli" method="get">
    	<div><input type="text" name="uid" /></div>
    	<input type="submit" value="登录" />
    </form>
    </body>
    </html>
    

    LoginController.class.php代码

    <?php
    namespace HomeController;
    use ThinkController;
    class LoginController extends Controller{
    	public function login(){
    		
    		//var_dump(get_defined_constants(true));
    		
    		//向TP里面注册变量
    		$this->assign("ceshi","张三");
    		//显示模板
    		$this->show();
    	}
    	public function chuli($uid){
    		//echo $_GET["uid"];
    		echo $uid;
    	}
    }
    

     

  • 相关阅读:
    79. Word Search
    97. Interleaving String
    74. Search a 2D Matrix
    73. Set Matrix Zeroes
    72. Edit Distance
    71. Simplify Path
    64. Minimum Path Sum
    shell编程 备份mysql数据库并发送到另一个服务器
    linux 命令执行的判断依据: ;,&&,||
    linux 数据流重定向
  • 原文地址:https://www.cnblogs.com/xiaohaihuaihuai/p/8566604.html
Copyright © 2020-2023  润新知