我在自定义联系人模块中收到了无效的CAPTCHA操作ID异常.我设法显示验证码,但模型验证规则会抛出无效的操作ID异常.以下是我的代码:
联系我们/控制器/ DefaultController.php
class DefaultController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
[
'actions' => ['captcha','index'],
'allow' => true,
],
]
]
];
}
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
public function actionIndex()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(setting::ADMIN_EMAIL_ADDRESS)) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh(); …Run Code Online (Sandbox Code Playgroud) 我正在构建一个基于Yii2高级模板的产品.
作为此产品及其未来部署的一部分,我尝试在常规Yii2迁移中自动创建与授权相关的表.
例如,当最终用户安装产品并运行常规Yii迁移命令时,他应该具有活动的全功能用户管理和授权.
要获得授权,Yii2 RBAC文档页面指出需要4个表(auth_*).文档声明它们是通过运行以下迁移创建的:
yii migrate --migrationPath=@yii/rbac/migrations
我想通过在将要存储的常规迁移中为他运行此特定迁移代码来抵消最终用户的这种额外麻烦common/migrations.
对此有什么简单的解决方案
如何在配置文件模块的索引视图文件中呈现视图文件.我试过这个:
<?=$this->render('/product/product/_search')?>
这是我得到的错误:
视图文件不存在:C:\ OpenServer\domains\zuppermart\frontend\modules\profile\views\product/product/_search.php`
我也试过了 <?=$this->render('//product/product/_search')?>
我收到这个错误:
视图文件不存在:C:\ OpenServer\domains\zuppermart\frontend\modules\profile\views\profile\modules // product/product/_search.php
我在Yii1.x有一个项目,现在我正在使用Yii2进行相同的项目
项目层次结构就是这样的
Project1(yii1)/all yii files + project2(yii2)
project2(yii2)/frontend + /common + /backend
Run Code Online (Sandbox Code Playgroud)
现在我想知道,如果是可以用project2/common/models在project1/protected/controllers
我怎样才能完成这项任务?
谢谢
我正在尝试使yii2验证我的ActiveForm字段,该字段应为数字且长度为8个字符.
以下是我在默认LoginForm模型中尝试过的yii2/advanced/backend,但不幸的是isNumeric验证器根本没有启动:
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// username should be numeric
['username', 'isNumeric'],
// username should be numeric
['username', 'string', 'length'=>8],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates if the username is numeric.
* This method serves as the inline validation for username.
*
* @param string $attribute the attribute currently being validated
* …Run Code Online (Sandbox Code Playgroud) 我想知道yii2 gridview复选框列中是否有任何内置选项,一次选择/取消选择所有行.
例如,如果我在gridview中有500条记录,并且我一次显示100条记录,那么我一次只能选择100条记录并执行任何批量操作.
我希望用户能够一次选择所有500条记录,并立即对这些记录执行任何批量操作.希望大家都能得到我的问题
我提出了一个建议,以警予在框架的业主github,他们已经证实,他们会做这种增强很快就好了,放在增强部分这一问题,所以希望他们将包括它很快,但在那之前引导我任何替代方式来实现这一目标
谢谢
我试图从终端运行控制台控制器,但我每次都会收到此错误
Error: Getting unknown property: yii\console\Application::user
Run Code Online (Sandbox Code Playgroud)
这是控制器
class TestController extends \yii\console\Controller {
public function actionIndex() {
echo 'this is console action';
} }
Run Code Online (Sandbox Code Playgroud)
这是concole配置
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'modules' => [],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params];
Run Code Online (Sandbox Code Playgroud)
我尝试使用这些命令运行它没有运气
php yii test/index
php yii test
php ./yii test
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我有一个更改密码引导模式,当用户单击更改密码导航栏菜单时将触发该模式.
我已将模态包含在页脚中.但是如何ChangePassword model instance将页脚布局文件传递给页脚?
可以beforeRender Or EVENT_BEFORE_RENDER用吗?如果是,怎么样?
正如所建议的那样,我将以下代码放在/ config/bootstrap.php中:
yii\base\Event::on(yii\base\View::className(), yii\base\View::EVENT_BEFORE_RENDER, function() {
$modelChangePassword = new frontend\models\ChangePassword;
$this->view->params['modelChangePassword'] = $modelChangePassword;
});
Run Code Online (Sandbox Code Playgroud)
但它给出了Using $this when not in object context错误.
我知道我在这里犯了错误,但我一整天都在寻找这个.我使用了yii2框架,我还是新来的,我想访问partone/two页面,partone/two页面有两个提交按钮,一个用于添加行,第二个用于验证输入
在PartoneController.php中
<?
public function actionTwo() {
if(\Yii::$app->user->isGuest) {
$this->goHome();
}
$models = [];
$val = "" ;
//Create array of items
Yii::trace("Lets start: ");
if(Yii::$app->request->post('addRow') == 'true'){
Yii::trace("hello");
Model::loadMultiple($models, Yii::$app->request->post('items'));
$model = new RelationForm();
array_push($models, $model);
return $this->render('two', ['items' => $models]);
}
if (Model::loadMultiple($models, Yii::$app->request->post('items')) && Model::validateMultiple($models))
{
Yii::trace("hello again");
$count = 0;
for($i = 0 ; $i < $models.length(); $i++){
if(strpos($relationShownCurrently, '' + $i) !== FALSE){
if(!$items[$i]->store()){
return $this->render('two', [ 'items' => $models …Run Code Online (Sandbox Code Playgroud) 我开发了Angular和Yii2 REST服务.在跨域有问题.下面添加我的angular&Yii2 REST代码.
AngularJs:(像' http://organization1.example.com ', ' http://organization2.example.com ',....)
$http.defaults.useXDomain = true;
$http.defaults.withCredentials = true;
$http.defaults.headers.common['Authorization'] = 'Bearer ' + MYTOKEN
Run Code Online (Sandbox Code Playgroud)
我来自Angular Controller的请求:
apiURL = 'http://api.example.com';
$http.get(apiURL + '/roles')
.success(function (roles) { })
.error(function () { });
Run Code Online (Sandbox Code Playgroud)
Yii2 .htaccess :( REST网址如' http://api.example.com ')
Header always set Access-Control-Allow-Origin: "*"
Header always set Access-Control-Allow-Credentials: true
Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "Authorization,X-Requested-With, content-type"
Run Code Online (Sandbox Code Playgroud)
Yii2我的行为:
public function behaviors() {
$behaviors = parent::behaviors();
$behaviors['corsFilter'] = [
'class' …Run Code Online (Sandbox Code Playgroud)