關(guān)于訪問的URL 不正確
我用的是這個(gè)http://localhost/test/index.php?m=Index&a=Index 發(fā)現(xiàn)用其實(shí)需要寫一個(gè)action 方法才可以, 也就是說(shuō)在thinkPHP3.2.6 里面是用的http://localhost/test/index.php?m=Index&a=action 才能訪問, 代碼如下:?
$module?=?isset($_GET['m'])?$_GET['m']:'Index'; $action?=?isset($_GET['a'])?$_GET['a']:'Index'; $mooc=new?$module(); $mooc->action(); class?index { function?__construct() { echo?'調(diào)用了Index?控制器'?; } function?index() { echo?'我是index?控制器的index方法'; } function?test() { echo?'我是index?控制器的index方法'; } function?action() { echo?'我是index?控制器的action?方法'; } } //?開啟調(diào)試模式?建議開發(fā)階段開啟?部署階段注釋或者設(shè)為false define('APP_DEBUG',True); exit?;
2017-04-05
$module?=?isset($_GET['m'])?$_GET['m']:'Index';
$action?=?isset($_GET['a'])?$_GET['a']:'Index';
?
$mooc=new?$module();
$mooc->(你這個(gè)action前邊少了$符號(hào)吧)action();
少了的話,就是只會(huì)調(diào)用action()方法,它不會(huì)根據(jù)傳入的參數(shù)進(jìn)行變化。