Giter VIP home page Giter VIP logo

Comments (2)

wuye1200 avatar wuye1200 commented on August 30, 2024

Controller

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

$session = \YII:$app->session;
$session->open();
if($session->isActive); //是否开启
$session->set(key,value);
$session->get(key)

cookies

$cookies  = \YII:$app->respones->cookies;
//设置
$data = array('name'=>‘user’,'value'=>'test');
$cookies -> add(key,value);
$cookies->remove('id');

获取cookies

$cookies = \YII::$app->request->cookies;
$cookies->getValue('user');

from blog.

wuye1200 avatar wuye1200 commented on August 30, 2024

视图

return $this - >renderPartial('index.php')//渲染视图
$this->rend('index');//

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.