休息关系注释问题

发布于 2024-12-15 16:49:15 字数 1492 浏览 1 评论 0原文

我遇到了一个严重的问题,事实上,我不太理解关系的休会命名约定。我个人认为应该用具体的例子来记录更多。希望,如果我理解它,我可以开始写一些例子。另外,如果有人很好地理解休会关系约定,以防万一,他可以在这里解释它,那就太好了

我有两个表,所有表名数据库中的 是型号名称的小写字母。所有字段名称与模型属性相同 帖子---->评论(一篇帖子可以有多个评论)

模型帖子:

<?php
/**
 * !Database Default
 * !Table post
 * !HasMany comment, Class:try.models.Comment,Key:postId
 */
class Post extends Model 
{
        /** !Column PrimaryKey, Integer, AutoIncrement */
        public $postId;

        /** !Column String */
        public $name;

}
?>

模型评论:

<?php
/**
 * !Database Default
 * !Table comment
 * !BelongsTo post
 */
class Comment extends Model {
        /** !Column PrimaryKey, Integer, AutoIncrement */
        public $commentId;

        /** !Column String */
        public $name;

}
?>

但是,当我执行以下操作时,我得到了错误

<?php
Library::import('try.models.Post');
Library::import('try.models.Comment');

Library::import('recess.framework.controllers.Controller');

/**

 * !RespondsWith Layouts

 * !Prefix Views: home/, Routes: /

 */

class TryHomeController extends Controller {



        /** !Route GET */

        function index() 
        {               

                $this->flash = 'Welcome to your new Recess application!';

                $Post= new Post(5);
                $Comments=$Post->comment();
        }



}

?>

但是,我收到此错误

try.models.Comment 尚未导入。

I'm running into a severe problem, In fact I'm not well understanding recess naming convention for relationship. I personally think it should be more documented with concrete examples. Hopefully, if i get to understand it, I can start to write some examples.Also, if someone has well understand Recess relationship convention well, in case, he can explain it here, it would be great

I have two table, all table names are in the database are the lower case of the model names. All fields names are same to the models' attributes
Post---->Comment(A Post can have several comments)

Model Post:

<?php
/**
 * !Database Default
 * !Table post
 * !HasMany comment, Class:try.models.Comment,Key:postId
 */
class Post extends Model 
{
        /** !Column PrimaryKey, Integer, AutoIncrement */
        public $postId;

        /** !Column String */
        public $name;

}
?>

Model Comment:

<?php
/**
 * !Database Default
 * !Table comment
 * !BelongsTo post
 */
class Comment extends Model {
        /** !Column PrimaryKey, Integer, AutoIncrement */
        public $commentId;

        /** !Column String */
        public $name;

}
?>

However, when I'm doing the following, I'm getting an error

<?php
Library::import('try.models.Post');
Library::import('try.models.Comment');

Library::import('recess.framework.controllers.Controller');

/**

 * !RespondsWith Layouts

 * !Prefix Views: home/, Routes: /

 */

class TryHomeController extends Controller {



        /** !Route GET */

        function index() 
        {               

                $this->flash = 'Welcome to your new Recess application!';

                $Post= new Post(5);
                $Comments=$Post->comment();
        }



}

?>

However, I'm getting this error

try.models.Comment has not been imported.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦冥 2024-12-22 16:49:15

查看 Post 模型中的 Class 行,

**
* !Database Default
* !Table post
* !HasMany comment, **Class:try.models.Comment**,Key:postId
*/

这里包含完整的类路径,try.models.Comment。您只需指定 Comment 作为要包含的类。确保您的文件名遵循 ClassName.class.php 约定。

Look in your Post model at the Class line

**
* !Database Default
* !Table post
* !HasMany comment, **Class:try.models.Comment**,Key:postId
*/

Here you are including the full classpath, try.models.Comment. You only need to specify Comment as the class to include. Be sure that your file names follow the ClassName.class.php convention.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文