$this->res()
to generate the absolute path to the resource file
$this->res('css/style.css');
The resulting connection ishttp://youdomain.com/static/css/style.css
3. Call the view controller's method in the layout file
$this->action()
You can call the method in the view controller by using it directly in the layout file , as in the following example
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="Keywords" content="<?php echo isset($keywords) ? $keywords : "默认关键词"); ?>"/>
<meta name="Description" content="<?php echo isset($description) ? $description : '默认描述'; ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo isset($title)?$title:'默认标题' ?></title>
<?php $this->loadRes() ?>
</head>
<body>
<?php echo isset($content)?$content:'' ?>
</body>
</html>
url
method connection can be automatically generated, if the method has an alias, the alias will be used first
$this->url('controller:action', array('key'=>'value'));
$this->to([controller:action, params, sec])
$this->view->link()
$this->display([data, method, http_response_status])
$this->view->display()
a connection of .
http://domain/skeleton/htdocs/web/controller/action/p1/1/p2/2
Use the controller's property inside the method to get the parameter's value: $this->params
namespace app\web\controllers;
use Cross\MVC\Controller;
class User extends Controller
{
function index()
{
print_r($this->params);
}
}
The result is printed as an associative index array and the value in this case is skeleton/app/web/init.php
url['type'] = 3
Array ( 'p1' => 1 'p2' => 2 )
The print result may vary according to the setting of the url item in the app configuration file
namespace app\web\controllers;
use Cross\MVC\Controller;
class User extends Controller
{
function index()
{
$USER = new UserModules();
}
}
If every action in the class depends on UserModules
it, you can put the work of initializing UserModules in the constructor:
namespace app\web\controllers;
use Cross\MVC\Controller;
class User extends Controller
{
/**
* @var UserModule
*/
protected $USER;
function __construct()
{
parent::__construct();
$this->USER = new UserModule();
}
function index()
{
}
}
9. Access the specified route in the view template
等效于 : http://up.kuman.com/api/getWithdrawInfo(将网址写成固定,但是这种方式有一个缺点,一般线上和本地调试不会用同一个域名,如果直接写成固定,到时上线后,还需要逐个更改我们定义的路由)
所以,在crossPHP中,还是推荐这种方式进行路由的指定