阿江
- 阿江 回答了问题 如何编辑或删除自己发表的提问?
一天之内可以编辑的,好象是不能删除吧,可以关闭
- 阿江 回答了问题 AJAX获取页面后跳转问题
Ajax调用是在JS中跳转的,不是在Php中:
$.ajax({ url:'/users/data-user', type:'post', dataType:'json', data:{"_csrf": "<?= Yii::$app->request->getCsrfToken()?>"}, success:function(result){ if(result.error!=''){ alert('error:'+result.error); location.href='users/index';//此处跳转页面 }else{ $('#userData').html(result.data); } }, error:function(xhr,txtStatus){ }, complete:function(xhr,txtStatus){ } });
/users/data-user.php
...... //返回错误信息$error,让前端进行跳转,为空则不跳转: return $this->asJason(['data'=>$data,'error'=>$error]);
- 阿江 2017-05-25 已签到连续签到67天,获得了20个金钱
- 阿江 回答了问题 使用自动登录后无法退出
自动登录的意思就是在cookie中保存_identity,重新打开浏览器服务器读取到客户端的_identity,查找对应的session,没有则自动生成新的session,加载登录。仔细理解一下这个基本概念。
'components' => [ 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true,//自动登录设置有效
- 阿江 回答了问题 init里判断重定向,用户缺失是为什么?
你的意思是没有跳转吗?试试这个:
return $this->redirect(['/login/index'])->send();
- 阿江 回答了问题 init里判断重定向,用户缺失是为什么?
$this->userInfo是怎么来的?
- 阿江 2017-05-24 已签到连续签到66天,获得了20个金钱
- 阿江 回答了问题 类似tab选项卡切换页面显示数据
前端触发请求,使用Ajax从服务器获取数据,然后再局部更新即可,你可以先了解一下Ajax更新!
- 阿江 回答了问题 模型中去调用控制器中的某一个方法怎么调
先解答你的问题:
\controllers\MyController.phpnamespace app\controllers; class MyController extends Controller{ public static function fun1{ echo "fun1"; } public function fun2{ echo "fun2"; } }
\models\MyModle.php
class MyModel extends \yii\base\Model{ public function modelfun{ //调用控制器中的静态方法fun1() \app\controllers\MyController::fun1(); //调用控制器中的实例方法fun2():先实例化,再调用其方法,不过一般没人这么干! $control=new \app\controllers\MyController(); $control->fun2(); } }
建议:你把发短信的方法移到模型中即可直接调用,一般不会在控制器中去写业务逻辑的!