调用R方法
R('控制器名/方法名',参数)
注:参数的类型为数组类型
例如:
DemoController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class DemoController extends Controller
{
public function index()
{
R('Demo1/aa');
$this->display();
}
}
Demo1Controller.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class Demo1Controller extends Controller
{
public function index()
{
$this->display();
}
public function aa()
{
$this->assign('word',"我是demo1控制器的aa方法");
}
}
调用公共方法
直接调用方法即可
例如:
Common/function.php
public function bb()
{
$this->assign('word',"我是公共bb方法");
}
DemoController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class DemoController extends Controller
{
public function index()
{
bb();
$this->display();
}
}
实例化类
$user = new 控制器名();
$user -> 方法名();
例如:
Demo1Controller.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class Demo1Controller extends Controller
{
public function index()
{
$this->display();
}
public function aa()
{
$this->assign('word',"我是demo1控制器的aa方法");
}
}
DemoController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class DemoController extends Controller
{
public function index()
{
$user = new Demo1Controller();
$user->aa();
$this->display();
}
}