我无法弄清楚如何在Yii中正确保存复选框值.我有一个MySQL列active,定义为tinyint.我有以下表单创建代码,如果值为1则正确显示复选框已选中,如果为0则未选中:
<?php echo $form->labelEx($model,'active'); ?>
<?php echo $form->checkBox($model,'active'); ?>
<?php echo $form->error($model,'active'); ?>
Run Code Online (Sandbox Code Playgroud)
并且保存表单的代码正确地更改了其他基于文本的值:
public function actionUpdate($id)
{
$model=$this->loadModel($id);
if(isset($_POST['Thing']))
{
$model->attributes=$_POST['Thing'];
if($model->save())
$this->redirect(array('thing/index'));
}
$this->render('update',array(
'model'=>$model,
));
}
Run Code Online (Sandbox Code Playgroud)
值active未保存.我哪里错了?
成功登录后,Yii不执行任何页面.
显示错误:
错误404无法解析请求"membersdet/index"
这membersdet是控制器ID,index是一个动作.
我有以下代码从db获取一些记录
$criteria = new CDbCriteria();
$criteria->condition = 't.date BETWEEN "'.$from_date.'" AND "'.$to_date.'"';
$criteria->with = array('order');
$orders = ProductOrder::model()->findAll($criteria);
Run Code Online (Sandbox Code Playgroud)
是否可以获取findAll使用的SQL?我知道你可以从调试控制台获取它.但我正在使用yiic.php在后台运行脚本
当我试图删除帖子时,我收到此错误:
Yii Error 400 The CSRF token could not be verified
Run Code Online (Sandbox Code Playgroud)
我不知道究竟是什么造成了这种情况以及它可能与之相关.这是我的动作删除:
public function actionDelete($id) {
if (Yii::app()->request->isPostRequest) {
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if (!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
protected function afterDelete()
{
parent::afterDelete();
Image::model()->deleteAll('name='.$this->id);
Date::model()->deleteAll('tbl_show_id='.$this->id);
Press::model()->deleteAll('tbl_show_id='.$this->id);
}
Run Code Online (Sandbox Code Playgroud) 我很想知道是否有一个脚本或其他可用于收集和生成控制器/项目中的Yii翻译消息
例如.如果我在控制器中有以下代码
Yii::t('blog', 'Your name');
Yii::t('category', 'Category name');
Run Code Online (Sandbox Code Playgroud)
它应该生成英文翻译消息文件blog.php和category.php以及消息目录中的上述字符串.如果有人知道某种方式,请告诉我.谢谢
我从不同的控制器和子域发送相同的表单数据.但在一种情况下,我需要禁用CSRF验证.
例:
登录表格:
位置1:主页example.com
位置2:account.example.com/login
地点3: gate.example.com
我需要禁用验证,以防我将数据从位置1发送到位置2.
我用了 $form = $this->beginWidget('CActiveForm',...
我怎样才能做到这一点?
我认为csrf cookie不是跨域的!
我们即将开始一个新项目,我们想要使用Yii.在阅读Yii网站后,我发现Yii 2 beta的发布日期已经设定为2014年初,并且由github判断,该里程碑准备好了94%.
选择Yii版本时,在这种情况下,我们最好的选择是什么?如果我们使用稳定的Yii 1,以后是否很容易将该代码更新为Yii 2.0,或者它将是一个完全重写还是一些糟糕的黑客攻击?或者如果我们使用Yii 2.0 alpha,那么更新会相对容易吗?alpha的不稳定性是可以的,我们无论如何都可能会在beta发布的时候处理基本的事情,例如身份验证,注册等?最后是使用最新的github提交(这是一个94%的完整测试版)一个好主意,还是处于半功能"开发"状态,可能根本不起作用?
Yii扩展程序的兼容性如何?如果我们选择Yii 2,我们是否会受限于相对较少的Yii 2扩展选择?
在Yii2中创建REST api是多么简单,我印象深刻.但是,我在理解基本身份验证时遇到了一些麻烦.我的需求非常简单,我希望我的解决方案能够效仿.
我在这里需要基本令牌认证.我现在甚至都不反对硬编码,但这就是我到目前为止所做的.
我有数据库表来保存我的单数令牌ApiAccess(id,access_token)
ApiAccess.php - 模型 - 注意:IDE在第一行显示语法错误
class ApiAccess extends base\ApiAccessBase implements IdentityInterface
{
public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['access_token' => $token]);
}
}
Run Code Online (Sandbox Code Playgroud)
Module.php - 在init()函数中
\Yii::$app->user->enableSession = false;
Run Code Online (Sandbox Code Playgroud)
我制作了一个ApiController,每个后续名词都会延伸
ApiController.php
use yii\rest\ActiveController;
use yii\filters\auth\HttpBasicAuth;
use app\models\db\ApiAccess;
class ApiController extends ActiveController
{
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
];
return $behaviors;
}
}
Run Code Online (Sandbox Code Playgroud)
目前,访问浏览器中的api端点会提示输入用户名和密码.通过REST客户端请求显示访问错误.
如何正确地将HttpBasicAuth与我的ApiAccess模型联系起来?
要么
如何对api访问令牌进行硬编码? (第一种选择显然是最好的)
我正在使用Yii2并一直在阅读主题和主题继承 ; 但有一些问题:
请考虑以下示例:
'view' => [
'theme' => [
'pathMap' => [
'@app/views' => [
'@app/themes/current',
'@app/themes/default',
],
],
'baseUrl' => '@web/themes/current',
'basePath' => '@webroot/themes/current',
],
],
Run Code Online (Sandbox Code Playgroud)
现在,假设我们请求主题文件foo; 据我了解,首先按以下顺序查找:
@app/themes/current/foo.php@app/themes/default/foo.php@app/views/foo.php现在想象foo.php在@app/themes/current/主题中找不到,所以它会使用找到的文件@app/themes/default/.
现在,考虑到baseUrl和basePath设置我有点困惑如何在这些情况下使用它们.
现在,想象一下foo.php引用文件里面的图像文件,这不是仍然会尝试查找@web/themes/current/images/myImage.jpg而不是@web/themes/default/images/myImage.jpg吗?
我有其中有一个字段的表`activated_at` timestamp NULL DEFAULT NULL,这意味着它可以包含时间戳,也可以是null和它的null默认.
我有另一个[gii-generated]搜索模型,在该search()方法中具有以下配置:
public function search($params)
{
$query = User::find();
// add conditions that should always apply here
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$andFilterWhere = [
'id' => $this->id,
'status' => $this->status,
'role' => $this->role,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'completed_files' => $this->completed_files,
// 'activated_at' => null, …Run Code Online (Sandbox Code Playgroud)