2

我做了

yiic shell "/path/to/my/app"

model *

crud users

我无法添加或更新用户。我可以列出它们,然后删除它们。我还以为我应该看到主键。

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(11) NOT NULL auto_increment,
  `user_username` varchar(25) collate latin1_general_ci NOT NULL,
  `user_username_clean` varchar(25) collate latin1_general_ci NOT NULL,
  `user_password` varchar(64) collate latin1_general_ci NOT NULL,
  `user_register_time` int(11) NOT NULL,
  `user_code` varchar(15) collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`user_id`)
) ENGINE=InnoDB;
4

4 回答 4

2

可能的原因可能是您在 config/main.php 中提供的数据库用户名/密码无权修改数据库。只是猜测,发布有关该问题的更多详细信息以更好地理解它。

于 2010-05-25T10:55:51.490 回答
1

看起来上面关于数据库权限的建议是答案,但只是一个友好的提示:新版本的 Yii 有一个新的可视化(GUI)CRUD 生成器,称为“Gii”。查看此处的说明,它比 yiic 好得多,并且可以解决创建 CRUD 代码的一些问题:

http://www.yiiframework.com/doc/guide/quickstart.first-app#generating-crud-code

于 2010-07-16T20:37:32.397 回答
1

The problem is while generating function loadModel in appController.php

The generator creates the function loadModel like this:

public function loadModel($id)
{
    $model=App::model()->findByPk((int)$id);   //  <- Error Line 
    if($model===null)
        throw new CHttpException(404,'The requested page does not exist.');
    return $model;
}

And the correct loadModel function is as follows:

public function loadModel($id)
{
    $model=App::model()->findByPk($id);   //  <- Fixed Line
    if($model===null)
        throw new CHttpException(404,'The requested page does not exist.');
    return $model;
}

I hope to have helped better understand the problem and correct them in the package without touching the Original of the generator, as it should appear in YII updates own correction.

于 2011-06-26T16:10:37.363 回答
0

启用非整数主键的补丁

--- yii-1.1.5.r2654/framework/cli/views/webapp/protected/config/main.php    2010-11-14 20:35:42.000000000 +0000
+++ yii-1.1.5.r2654/framework/cli/views/webapp/protected/config/main.php    2010-12-09 16:59:01.783001000 +0000
@@ -42,4 +42,5 @@
                '/'=>'/view',
                '//'=>'/',
+               '//'=>'/',
                '/'=>'/',
            ),

--- yii-1.1.5.r2654/framework/gii/generators/crud/templates/default/controller.php  2010-11-14 20:35:45.000000000 +0000
+++ yii-1.1.5.r2654/framework/gii/generators/crud/templates/default/controller.php  2010-12-09 16:47:54.053001002 +0000
@@ -163,5 +163,5 @@
    public function loadModel($id)
    {
-       $model=modelClass; ?>::model()->findByPk((int)$id);
+       $model=modelClass; ?>::model()->findByPk($id);
        if($model===null)
            throw new CHttpException(404,'The requested page does not exist.');

--- yii-1.1.5.r2654/framework/gii/GiiModule.php 2010-11-14 20:35:45.000000000 +0000
+++ yii-1.1.5.r2654/framework/gii/GiiModule.php 2010-12-09 16:49:22.183001002 +0000
@@ -53,4 +53,5 @@
  *             'gii/'=>'gii/',
  *             'gii//'=>'gii//',
+ *             '//'=>'/',
  *             ...other rules...
  *         ),
于 2010-12-10T09:56:30.633 回答