Open wuye1200 opened 6 years ago
namespace app\controller;
use yii\web\Controller;
class HelloController extends Controller {
public function actionIndex(){
echo 'hi';
}
}
$request = \YII: $app-> request;
$request = request -> get('id'); //获取url里面id参数 get方式
$request = request -> post('id'); //获取url里面id参数 post方式
if( $request -> isGet) //判断是否为get方式
api [http://www.yiichina.com/doc/api/2.0/yii-web-request ]
$res = \YII::$app->response;
$res->statusCode = '400';
$res->headers->add('prama','no-cache');
$this->redirect('http://www.baidu.com');//重定向
$res->headers->add('content-disposition',''attachment;filename="a.png"');//下载文件
$res->sendFile('./test.txt');//下载文件
$session = \YII:$app->session;
$session->open();
if($session->isActive); //是否开启
$session->set(key,value);
$session->get(key)
$cookies = \YII:$app->respones->cookies;
//设置
$data = array('name'=>‘user’,'value'=>'test');
$cookies -> add(key,value);
$cookies->remove('id');
$cookies = \YII::$app->request->cookies;
$cookies->getValue('user');
return $this - >renderPartial('index.php')//渲染视图
$this->rend('index');//
命名空间
namespace 指定当前文件的命名空间
例如
use