休息关系注释问题
我遇到了一个严重的问题,事实上,我不太理解关系的休会命名约定。我个人认为应该用具体的例子来记录更多。希望,如果我理解它,我可以开始写一些例子。另外,如果有人很好地理解休会关系约定,以防万一,他可以在这里解释它,那就太好了
我有两个表,所有表名数据库中的 是型号名称的小写字母。所有字段名称与模型属性相同 帖子---->评论(一篇帖子可以有多个评论)
模型帖子:
<?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 Post 模型中的 Class 行,
这里包含完整的类路径,try.models.Comment。您只需指定 Comment 作为要包含的类。确保您的文件名遵循 ClassName.class.php 约定。
Look in your Post model at the Class line
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.