使用Yii,我想删除今天不是的所有行.
我的解决方案好吗?
$query = "delete from `user_login_hash` where `day`!='".(date('Y-m-d',time()))."'";
Yii::app()->db->createCommand($query);
Run Code Online (Sandbox Code Playgroud) 我正在努力工作环境文件夹的重点.
最初我有一个想法,你可以将网络服务器指向文件夹中的不同dev和prod文件environment夹,但在读了一下之后我意识到情况并非如此.
在Yii 1中你只需要多个即可解决这个问题index.php:
index.phpindex-local.php那么问题是这个新的环境结构实际上给我带来的好处是什么?
我正在尝试使用数据提供程序以降序日期顺序为每个用户显示数据库,这适用于控制器上的Yii 1:
$DataProvider = new CActiveDataProvider('ModelName', array(
'criteria' => array(
'condition' => 'user_id=' . Yii::app()->user->id,
'order' => 'submitted_dt DESC',
),
'pagination' => array(
'pageSize' => 20,
),
));
Run Code Online (Sandbox Code Playgroud)
我在Yii 2中尝试这个:
$DataProvider = new ActiveDataProvider([
'query' => ModelName::find(),
'criteria' => [
'condition' => 'user_id=' . Yii::$app->user->identity->id,
'order' => 'submitted_dt DESC',
],
'pagination' => [
'pageSize' => 20,
],
]);
// get posts in the current page
$Model= $DataProvider->getModels();
Run Code Online (Sandbox Code Playgroud)
我得到的错误是未知属性:yii\data\ActiveDataProvider::criteria.那么设置这个条件和顺序的方法是什么?欢迎所有建议
我是YiiMongoDbSuite的作者,这个扩展使ActiveRecord模式中的MongoDB支持非常类似于核心Yii中已有的SQL.
我的代码变得非常流行,因为它的目的是为了缩短学习曲线而与原始的Yii方法几乎相同,只有两个主要区别是缺少关系支持(因为在mongo中没有这样的东西) )和不同的标准对象.
我发现我的代码非常有趣且易于使用,特别是对于已经使用Yii的mongo新手,但我也发现/思考几个月后开发新功能并使用我的代码,ActiveRecord设计模式不是一个好选择对于面向文档的DB而且我也认为AR模式本身是mongo真实权力的限制(即新的Doctrine已经放弃了AR模式,即使在SQL db中也是如此).
所以我的问题是,可以使用哪些替代设计模式来"释放"MongoDB/Document面向数据库的全部"功能"?
我正在使用有效记录.让我们称之为产品型号.如何使用活动记录从"tbl_product"中选择"%发球%"这样的名称来选择最小值(价格)?
我正在做一个需要身份验证的应用程序.在应用程序的索引页面中,我指定了这样的访问规则
public function accessRules() {
return array(
array('deny',
'actions'=>array('index','register','login','password'),
'users'=>array('@'),
),
array('allow',
'users'=>array('*')
),
);
}
Run Code Online (Sandbox Code Playgroud)
在第一条规则中,操作'index','register','login'和'password'对于经过身份验证的用户是不可访问的.但是,我不想显示此消息
Unauthorized
You are not authorized to perform this action.
You do not have the proper credential to access this page.
If you think this is a server error, please contact the webmaster.
Run Code Online (Sandbox Code Playgroud)
...当经过身份验证的用户尝试访问这些操作时.相反,我想将它们重定向到另一个页面.如果我能在第一条规则上做这样的事情会很有用
array('redirect',
'actions'=>array('index','register','login','password'),
'users'=>array('@'),
'url'=>array('home/index'),
),
Run Code Online (Sandbox Code Playgroud) 我正在使用Yii框架,404如果在数据库中找不到重新编码,我想生成错误.是否有任何聪明的方式,所以Yii default error handler应该调用.
提前致谢.
今天我收到错误参数号无效:更新数据时我的yii应用程序中没有定义参数.然后我才知道我的sql数据库表列包含带" - "符号的名称,即"table-post"等.
然后我用"_"改变了" - ",一切正常.
这是查询片段(我用"_"替换了" - ")
/* percentage losses senser*/
$attributes['totlcommloss_sensor'] = $_POST['totlcommloss_sensor'];
$attributes['asp_hour_sensor']= $_POST['asp-hour_sensor'];
$attributes['asp_daily_sensor'] = $_POST['asp-daily_sensor'];
$attributes['asp_weekly_sensor']= $_POST['asp-weekly_sensor'];
$attributes['asp_monthly_sensor'] = $_POST['asp-monthly_sensor'];
$attributes['asp_5_day_senser']= $_POST['asp_5_day_senser'];
/* cost losses */
//$attributes['costlosshourly'] = $_POST['acs-hourly'];
if (0 != intval($user['id'])) {
$command->update('alarm_settings', $attributes, 'id=:id', array(':id' => intval($user['id'])));
}
else {
$NumberOfRowsEffected = $command->insert('alarm_settings', $attributes);
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么这个例子显示错误?提前谢谢了.
我想使用限制12,20从db获取数据.
这是我的代码:
$Query = new Query;
$Query->select(['um.id as USERid', 'um.first_name', 'um.last_name', 'um.email', 'COUNT(g.id) as guestCount'])
->from('user_master um')
->join('LEFT JOIN', 'guest g', 'g.user_id = um.id')
->limit(12,20)
->groupBy('um.id')
->orderBy(['um.id' => SORT_DESC]);
$command = $Query->createCommand();
$evevtsUserDetail = $command->queryAll();
Run Code Online (Sandbox Code Playgroud)
它不起作用.它给了我所有的行.我也试过 - >限制([12,20]),不工作.
但是当我使用 limit(12)时,我得到了12行.
我想获得限制12,20的行.在我的代码中我应该怎么做?