drodata
- drodata 回答了问题 yii子模块如何调用父模块的动作
在
frontend/site/index
前面加上/
即可:return $this->redirect('/frontend/site/index');
Guide Handling Requests - Routing and URL Creation - Creating URLs 里面讲到:
If the route has no leading slash, it is considered to be a route relative to the current module and will be prepended with the uniqueId value of the current module.
你可以读读这节内容,了解一下 Yii 将 route 转换成 url 的过程。
- drodata 回复了话题 配置里 日志categories代表的什么
和
levels
类似,都是起过滤作用的。你可以把categories
的值改成['yii\db\*']
, 然后在 Yii Debugger 里查看一下日志信息的变化感受一下。参考 Guide Handling Requests → Logging → Log Targets → Message Filtering 。 这种引入方法虽不推荐,但只要处理好加载顺序,也是可以让 Validate 插件工作的。
把
ExportController
内actionIndex()
里面的return $this->render('index');
换成
return $this->renderPartial('index');
试试。
Actions 分两种:Inline Actions 和 Standalone Actions. 前者以 action methods 形式存在,比如
actionIndex()
; 后者以类的形式存在,这个类必须继承自yii\base\Action
或其子类。site/error
action 是以 Standalone Actions 形式存在的:class SiteController extends Controller { ... public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], ]; } ... }
所以在
SiteController
内没有actionError
method.参考 Guide 2.0 中 Application Structure → Controllers → Creating Actions 内容。
- drodata 回复了话题 attributes 问题?
在 User 类的 rules() 方法内加上如下一句试试:
public function rules() { return array( ... array('password2', 'safe'), ); }
语句
$user_model->attributes = $_POST['User'];
默认只会将 User 类中的 safe attributes 传递给$user_model->attributes
, 所谓 safe attributes 就是那些在 rules() 方法声明了验证规则的那些属性。上面的
array('password2', 'safe')
就是在声明验证规则,常见的还有array('password2', 'required')
. - drodata 回复了话题 Yii 收集表单信息
checkBoxList()
生成复选框,通过$model->attributes=$_POST['Model']
它的值(数组或空字符)就到 model 中了。$model->save()
前对搜集到的值进行处理,转换成表中对应列接受的数据格式就行了,转换过程可以自定义一个 Validator。 - drodata 回复了话题 实现删除一条数据时,更新剩余数据的时间字段
惭愧,自己之前接触的 udpate 操作都是针对单条记录,不知道 update() 和 delete(), find() 一样有对应针对多条记录的 updateAll().
- drodata 回复了话题 实现删除一条数据时,更新剩余数据的时间字段
$model = new Table; $model->last_modified=date("Y-m-d H:i:s",time()); if(!$model->save()){ echo date("Y-m-d H:i:s",time()); }
你想更新的是表中所有剩余记录中 'last_modified' 列的值,而 ActiveRecord Class 是针对单条记录行的操作类,所以上面那么写不行。我也刚了解 Yii, 你试试下面这个:
Yii::app()->db->createCommand()->update('table',array('last_modified'=>date("Y-m-d H:i:s",time())));