一个实例就代表表中一行,所以用thinkphp的模型部分有种别扭的感觉。
例如:
$User = D('User');
dump($User->where(array('id'=>17))->select());在thinkphp中模型类实例代表表,array代表一行记录。最直接的方法类似下:
$user = UserModel::findById(17);
$user->age=20;
$user->save().不知道是不是因为php5.3的限制而必须这么实现,如果是的话,求支持php5.4.我再举些例子(来自yii2):
public function addTaxonomy($taxonomy_id)
{
$relation = new ArticleTaxonomyRelationship();
$relation->taxonomy_id = $taxonomy_id;
$relation->article_id = $this->id;
$relation->user_id = $this->user_id;
$relation->taxonomy_order = $this->user_id;
if (!$relation->save()) {
throw new DuplicateRecordException($this->errors);
}
}
public function deleteTaxonomy($taxonomy_id)
{
$relation = ArticleTaxonomyRelationship::findOne(['article_id' => $this->id, 'taxonomy_id' => $taxonomy_id]);
if (!$relation) {
throw new NullPointerException("category or tags are not related to this article");
}
return $relation->delete();
} 最佳答案