主要用来设置cookie、获取cookie和清除cookie。可以设置cookie的失效时间、作用域等。属于InitPHP框架工具类,需要通过$this->getUtil()方法获取。
$cookie = $this->getUtil('cookie');
接口:$cookie->set($name, $val, $expire = '', $path = '', $domain = '') 设置cookie值
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $name | String | 是 | 设置的Cookie名称 |
| $val | String | 是 | Cookie值 |
| $expire | Int | 否 | 失效时间 |
| $path | String | 否 | cookie路径 |
| $domain | String | 否 | cookie作用的主机 |
接口:$cookie->get($name) 获取cookie
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $name | String | 是 | Cookie名称 |
接口:$cookie->del($name) 删除cook
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $name | String | 是 | Cookie名称 |
接口:$cookie->is_set($name) 是否存在cookie
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $name | String | 是 | Cookie名称 |
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$cookie = $this->getUtil('cookie');
$cookie->set('test', 'testVal');
$test = $cookie->get('test');
$this->getTestService()->test();
$this->view->display(); //模板显示
}
public function test() {
echo 'Hello World';
}
/**
* @return testService
*/
private function getTestService() {
return InitPHP::getService('test','test');
}
}