6月13日 控制器

自写控制器:

MainController.class.php:

<?php
namespace Home\Controller;
use Think\Controller;
class MainController extends Controller
{
    //前置操作
    public function _before_XianShi()
    {
        echo "显示之前";
    }
    
    public function XianShi()
    {   
echo $_POST["name"];
echo "主页面";
//传参数
echo $name.$age;
//读取配置 /*$model = C('URL_MODEL'); echo $model; */ //动态配置 /*C('URL_MODEL',0); echo U("XianShi");*/ } //后置操作 public function _after_XianShi() { echo "显示之后"; } public function CeShi() {
//注册变量
   //$this->assign("text","hello");
//调用模板显示 //
$this->display();
var_dump(get_defined_constants(true));//常量信息 }
public function login()
 {
  //实现两个逻辑,显示,登录
  if(empty($_POST))
  {
   $this->display();
  }
  else
  {
   //实现登录
   echo "实现登录";
  }
  
 } }

浏览器中输入http://localhost:8080/thimk/index.php/Home/Main/XianShi/name/li/age/22即可运行显示

 

如要运行CeShi(),还要在View中建文件夹Main,在该新建文件夹中建CeShi.html文档

CeShi.html:

<head>
<meta charset="utf-8" />
<title>无标题文档</title>
</head>

<body>
<a href="/thimk/index.php/Home/Main/XianShi/name/li/age/22">调用显示操作</a>

<div><{$text}></div>
<form action="__CONTROLLER__
/XianShi" method="post">
<input type="text" name="name" />
<input type="submit" value="提交" />
</form>
</body>

浏览器中输入http://localhost:8080/thimk/index.php/Home/Main/CeShi即可运行显示

 

Login.html:

<head>
<meta charset="utf-8" />
</head>

<body>
<form action="__ACTION__" method="post">
<input type="text" name="uid" />
<input type="password" name="pwd" />
<input type="submit" value="提交" />
</form>
</body>

 

posted @ 2016-06-13 23:17  D董小姐  阅读(151)  评论(0编辑  收藏  举报