php - 在 Grocery CRUD + Codeigniter 中设置控件的默认值

标签 php mysql codeigniter crud grocery-crud

我需要在 Grocery CRUD 中设置字段的默认值。

基本上,相应的数据列 IsActive 设置为 NOT NULL

我需要看到在添加记录时,IsActive 应该设置为 truefalse 而不是 NULL默认。

我在整个 Internet 上寻找引用,但没有找到完美的解决方案。

当前 View (在添加模式下)

enter image description here

因此,如果我没有将 rules 设置为 required,表单将向数据库发送一个 NULL

虽然我需要这样的东西(默认情况下)。 enter image description here

这样用户就不需要添加值了(不强制设置字段为true of false)

最佳答案

您可以在数据库级别为列设置默认规则,而不管任何框架/库。使用 DEFAULT 关键字。

   IsActive ENUM('active','inactive') NOT NULL DEFAULT 'active'

关于php - 在 Grocery CRUD + Codeigniter 中设置控件的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25009321/

相关文章:

php - xml :lang 上的 XSD 验证错误

mysql - ColdFusion:如何清除数据库行中的特定字段

php - 在 Windows 中向 PHP 添加 Mysqli 扩展时出错

c# - SubSonic:TableColumn 的 MaxLength(超出)

php - 左加入所有主题仅按粘性最后帖子顺序和最后帖子 DESC

php - htaccess 资源被解释为样式表但以 MIME 类型 text/html 传输

javascript - 将 JavaScript 值传递给 PHP 或其他 PHP 类 (codeigniter)

php - 模型文件 codeigniter 中的多个查询

php - 代码点火器 : delete from 2 tables and image from folder

php - PHP 中的 authz svn 文件解析器