在web.php我有这个
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
],
],
Run Code Online (Sandbox Code Playgroud)
这个文件夹的apache配置像这个php.conf文件
<VirtualHost *:80>
AssignUserId alexzander alexzander
ServerName localhost
DocumentRoot /home/alexzander/Dropbox/study/3year/2/php/
<Directory /home/alexzander/Dropbox/study/3year/2/php/>
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
Order allow,deny
Allow from all
Require all …Run Code Online (Sandbox Code Playgroud) 我用Yii2编写了我的网站.当我刷新我的网站时,它就像Ctl + F5,并且我的网站的所有font awesome和所有缓存再次重新加载.看起来好像我第一次打开页面.
我如何设法使用电子邮件地址登录,而不是使用标准版(用户名+密码).我在我的数据库中输入了我的用户的网站,但有没有办法将其更改为使用电子邮件地址而不是该用户名,因为当我使用Gii时,我遇到了很多错误,即使我尝试修复这些错误
我正在使用Yii2高级版 ; 并有一个问题.
码:
$model = \Yii::createObject($this->modelClass);
if ($model->load($temp, '') && $model->validate()) {
$data = $model;
}
Run Code Online (Sandbox Code Playgroud)
$temp - 是模型数据阵列;
$this->modelClass - 动态模型类名;
代码在cli模式下运行(Yii2控制台应用程序),modelClass- 来自backend应用程序的模型.
它在方法中崩溃了load:
Exception 'ReflectionException' with message 'Class require does not exist'
in /path/to/project/vendor/yiisoft/yii2/di/Container.php:422
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为模型Brand 有效,但类似的其他模型却没有.但是,模型对象已成功创建.
更新类别模型代码
<?php
namespace backend\models;
/**
* Category model
*/
class Category extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%category}}';
}
/**
* …Run Code Online (Sandbox Code Playgroud) 我是新来的,我不能在这里发表评论
当我试图在页脚中获得总和时,我遇到了问题.
我在控制器中的代码:
$searchModel = new ReceiptsSearch();
$sum = new ReceiptsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'sum'=>$sum,
]);
Run Code Online (Sandbox Code Playgroud)
我的SearchModel代码:
public function search($params)
{
$query = Receipts::find();
$sum = $query->sum('price');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->joinWith('patient');
$query->andFilterWhere([
'id' => $this->id,
'price' => $this->price,
'reg_date' => $this->reg_date,
]);
$query->andFilterWhere(['like','patient.patient_name',$this->patient_id]);
return $dataProvider;$sum;
}
Run Code Online (Sandbox Code Playgroud)
我的观点页面
<?= GridView::widget([
'dataProvider' => $dataProvider,$sum,
'filterModel' => $searchModel,
'showFooter' => …Run Code Online (Sandbox Code Playgroud) 在规则中,我有一个带有html文本的自定义消息:
[ 'user_email', 'required', 'message' => 'Don\'t have one? <a href="/contact-us">Give us a call</a>' ],
Run Code Online (Sandbox Code Playgroud)
我的表格:
<?php $form = ActiveForm::begin( [
'enableAjaxValidation' => true,
'validationUrl' => '/user/validate-register',
] ); ?>
<?= $form->field( $model, 'user_email', [
'errorOptions' => [
'encode' => false,
]
] )->textInput( [ 'maxlength' => true ] ) ?>
Run Code Online (Sandbox Code Playgroud)
当我输入errorOptions时,不会显示错误消息...它突出显示为红色,但不显示内联消息.
随着errorOptions出现任何错误消息在所有
我已经使用内置的yii2函数来设置会话.由于某些要求,我无法使用内置的yii2登录.
所以我使用以下设置会话:
Yii :: $ app-> session-> set('unique_code','xxxx');
在我的config/main.php文件中
'session' => [
// this is the name of the session cookie used for login on the frontend
'name' => 'project-frontend',
'timeout' => 60*60*24*30,
],
Run Code Online (Sandbox Code Playgroud)
但是一段时间后用户仍然会从网站注销.
那么在这种情况下如何增加会话超时?
我想用enablePrettyUrl = true将我的控制器映射到urlManager.
当类的名称是Ts4Controller,它映射得非常好
'https://' . $configDomain['siteMainDomainName'] . '/ts4'=> 'ts4/index',
Run Code Online (Sandbox Code Playgroud)
但当我将控制器名称更改为TheSims4Controller和
'https://' . $configDomain['siteMainDomainName'] . '/ts4'=> 'thesims4/index',
Run Code Online (Sandbox Code Playgroud)
它不起作用,它将得到404错误.
Yii 2.0中是否有对控制器名称的一些要求?
非常感谢你!
我有两个表A和B,关系"A有很多B".A可能没有任何B记录.
我需要编写一个查询,它只会选择那些在B中有相关记录的A记录.应忽略没有相关B记录的记录.使用Yii2活动记录我也试图加载所有A记录与急切加载相关的B记录.所以这就是我所拥有的:
Movies::find()->with('shows')->all();
Run Code Online (Sandbox Code Playgroud)
如何添加必要条件以过滤掉没有节目的电影?如何在依赖于节目数据的电影上添加任何条件?
我是Yii 2的新手,通常我使用Yii 1开发Web应用程序,现在Yii有新版本的Yii(Yii 2),我真的需要去Yii 2吗?Yii 1有安全隐患吗?
因为我看到Yii 2完全从Yii 1改变了.