yii2 控制器渲染】的更多相关文章

render() : 渲染一个 视图名并使用一个 布局返回到渲染结果. renderPartial() : 渲染一个 视图名并且不使用布局. renderAjax() : 渲染一个 视图名并且不使用布局, 并注入所有注册的JS/CSS脚本和文件,通常使用在响应AJAX网页请求的情况下.…
yii1中, 若存在如下控制器 class BindController extends CController { public function actionGetMobilePhone () { // some code... } } 那么, 通过访问 http://your-domain-name/bind/getMobilePhone  就可以访问到 以上代码如果在yii2中, 访问的时候, 就需要 http://your-domain-name/bind/get-mobile-pho…
Yii2,layout中使用Controller的值,Controller向layout传值的两种方式. yii2中在通过Controller向layout中传值,layout中访问Controller中的值, 1.第一种,通过layout变量数组赋值 $view = Yii::$app->view; $view->params['layout_data'] = '传给layout的值'; 2.第二种,在layout直接访问Controller的成员属性 首先在Controller中定义一个公…
如果模块名称或者控制器名称或者动作名称是用的骆驼格式的命名写法,那么路由里面的每个大写单词之间都要用“-”来连接.如 DateTimeController::actionFastForward 相应的路由为 date-time/fast-forward. 例如:http://dfms.com/backend/web/api-test/test-upload api-test是控制器名字 test-upload是方法名字…
render渲染.renderPartial渲染部分.renderContent.renderAjax.renderFile ① render显示view和layout ② renderPartial只显示view ③ renderContent只渲染layout ④ renderFile显示指定的文件,是最基础的方法, renderAjax,renderPartial最终都是调用renderFile. ⑤ renderAjax只显示view,以ajax方式渲染页面,可以配合js/css实现各种…
控制器生命周期 http://www.yii-china.com/doc/guide/structure_controllers.html 处理一个请求时,应用主体 会根据请求路由创建一个控制器,控制器经过以下生命周期来完成请求: 在控制器创建和配置后,yii\base\Controller::init() 方法会被调用. 控制器根据请求操作ID创建一个操作对象: 如果操作ID没有指定,会使用yii\base\Controller::defaultAction默认操作ID: 如果在yii\bas…
Yii::$app->response->format = Response::FORMAT_JSON; $data = User::find()->where([])->asArray()->one(); return ['code'=>200, 'msg'=>'成功','data'=>$data]; 结果 使用ajax 获取的数据 console.log()出来…
h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child { margin-top: 0; padding-top: 0; } a:first-child h1, a:first-child h2, a:first-child h3, a:fi…
想要了解更多YII,PHP方面内容,请关注本博客. 基础总结 1.修改默认控制器/方法 yii默认是site控制器,可以在web.php中设置$config中的'defaultRoute'='xxxx';使用自定义默认的控制器.也可以改写Yii::$app->defaultRoute属性. yii的默认方法是index,可以在vender/yiisoft/yii2/base/Controller.php 中进行初始设置,也可以在控制器中改写defaltAction='action'. 2.添加独…
控制器LoginController.php <?php namespace backend\controllers; use Yii; use yii\debug\models\search\Log; use yii\web\Controller; use backend\models\Login; use frontend\models\ContactForm; use Illuminate\Http\Request; use yii\web\Session; use backend\con…