yii save model return id null

    /**
     * Creates a new model.
     * If creation is successful, the browser will be redirected to the ‘view‘ page.
     */
    public function actionCreate()
    {
        $news=new News;
        $news_item = new NewsItem;
        $news->item = $news_item;
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($news);
        if (isset($_POST[‘News‘])) {
            $news->attributes=$_POST[‘News‘];
            if ($news->save()) {
                $_POST[‘NewsItem‘][‘header_id‘] = $news->id;
                $news_item->attributes=$_POST[‘NewsItem‘];
                if ($news_item->save()) {
                    $this->redirect(array(‘view‘,‘id‘=>$news->id));
                }
                else {
                    $news->deleteByPk($news->id);
                    $this->redirect(array(‘admin‘));
                }
            }
        }
        $this->render(‘create‘,array(
            ‘model‘=>$news,
        ));
    }

原来不是别的bug,因为 数据库中没有设置 id主键为 autoincrement

yii save model return id null

时间: 2024-08-26 13:47:23

yii save model return id null的相关文章

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"报错

出现问题的原因: 内存用户验证时,Spring boot 2.0.1引用的security 依赖是 spring security 5.X版本,此版本需要提供一个PasswordEncorder的实例,否则后台汇报错误: java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" 并且页面毫无响应. 解决方法: 创建PasswordEncorder的实现类MyPassw

There is no PasswordEncoder mapped for the id "null"

因为Spring-Security从4+升级到5+,导致There is no PasswordEncoder mapped for the id “null”错误. 解决方案: 1.可在密码验证类中添加 @Bean public static NoOpPasswordEncoder passwordEncoder() { return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance(); } 2.或者在xml配置文件中添加 <b:be

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

在spring security中设置默认的登录人的信息,遇到的异常信息: java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null” 有些版本不要求这样子做,所以就不会有该问题的发生, 我现在用的是5.0版本,强制要求提供一个,所以我们就给一个PasswordEncoder给他. 我们也可以使用Spring自带的PasswordEncoder.为了方便起见,我们以明文形式存密码

解决java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id &quot;null&quot;

问题描述: 使用springboot,权限管理使用spring security,使用内存用户验证,但无响应报错: java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" 解决方式 ①: 创建MyPasswordEncoder类实现PasswordEncoder,加注解  @Component @Component public class MyPasswordEn

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id &quot;null&quot;

今天在配置spring-security.xml配置文件时出错 错误如下: 严重: Servlet.service() for servlet [security] in context with path [] threw exception java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" at org.springframework.security.c

Yii 2 —— Model表前缀

1.1  Model表前缀 在大多数系统中,对于数据库的表名称都喜欢在前面增加一个前缀,譬如ecshop系统的表名称,都有前缀"ecs_",在它们的代码中到处充斥着如下代码: $GLOBALS['ecs']->table('goods') 这种代码的目的是把前缀"ecs"和后面的名称拼接起来获得"ecs_goods"这样实际的表名称.为什么不直接拼接字符串"ecs_"和"goods"?因为在安装时,是

Playframework - 如何解决两个JPA同时访问一个数据库但是不更新Model的id名字

当使用两个JPA访问同一个数据库时,由于数据库中本来的id字段不是使用默认的"id"为名字,如何在第二个JPA链接数据库时不会自动添加一个"id"字段,造成后面逻辑上的错误 答案是Model类不继承Model,而是继承更加低层的 public class User extends GenericModel

Yii里model验证的小技巧

例如:需要判断,字符长度在12-20之间,最大长度的提示语用tooLong,最小提示语言用tooShort array('pay_order', 'length', 'max' => 20, 'tooLong' => '字符长度在12-20位之间', 'min' => 12, 'tooShort' => '字符长度在12-20位之间', 'on' => 'fahuo'), 情景模式:如果自己的model里的的验证不想给别人造成麻烦,必定model都是大家公用的,那么用情景模式

30分钟搞定yii的gridview,你可能只看这一篇就够了 (包含基本配置,下拉筛选,多选删除)

view代码 <?php /* @var $this yii\web\View */ /* @var $form yii\bootstrap\ActiveForm */ /* @var $model \common\models\LoginForm */ use yii\helpers\Url; use yii\helpers\Html; use common\helps\Helps; use common\helps\ArrayHelper; use yii\grid\GridView; us