zoukankan      html  css  js  c++  java
  • 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;
    	}
    }
    

     

  • 相关阅读:
    调度器2—cat /proc/<pid>/sched内容分析
    调度器1—相关接口和命令行工具
    Java中的String类
    Java中的数组
    代码访问使用Let's Encrypt证书的网站提示certificate has expired的解决方法
    Linux环境Clion使用Protobuf
    PyTorch Dataloader读取时如何在进程之间传输数据
    6 安装Grafana 展示promethues数据
    5 Prometheus relabel配置
    4 PromQL
  • 原文地址:https://www.cnblogs.com/xiaohaihuaihuai/p/8566604.html
Copyright © 2011-2022 走看看