简体   繁体   English

Kohana-ORM_Tree

[英]Kohana - ORM_Tree

Found a couple of links suggesting using 'ORM_Tree' to handle a self-referential table: 找到了一些建议使用'ORM_Tree'处理自引用表的链接:

However, get an error from the controller saying 'Class ORM_Tree' not found. 但是,从控制器收到一条错误消息,提示未找到“ Class ORM_Tree”。 My model is as follows: 我的模型如下:

class Model_Article extends ORM_Tree {
    protected $children = "categories";
}

I am utilizing version 3.3.1 with the following in the controller: 我正在控制器中使用以下版本的3.3.1:

class Controller_Category extends Controller{

    //View
    public function action_index(){
        $categories = ORM::factory('Category')->find_all();
        $view = new View('category/index');
        $view->set('category', $categories);
        $this->response->body($view);
    }
}

Was the class removed from version 3.3.1? 该类是否已从3.3.1版本中删除? If so, does anyone have suggestions for handling a self-referential table as shown below: 如果是这样,是否有人对处理自引用表提出建议,如下所示:

category_id - int(11) - No category_id-int(11)-否
category_name - varchar(45) - No category_name-varchar(45)-否
category_description - varchar(250) - Yes - NULL category_description-varchar(250)-是-NULL
__parent_id - int(11) - Yes - NULL __parent_id-int(11)-是-NULL

Hopefully, I got that table clear enough to understand. 希望我能清楚地理解该表。 The __parent_id has a foreign-key relationship to the category_id. __parent_id与category_id具有外键关系。 The __parent_id can be null (to allow for a root or even several top-level). __parent_id可以为null(以允许root或什至几个顶级)。

Any suggestions would be greatly appreciated as I had very high hopes to utilize the tree in a project. 任何建议都将不胜感激,因为我非常希望在项目中利用这棵树。 Please forgive if this has been answered elsewhere (please understand that I did not ask until I had 'googled' and even 'yahooed'). 如果您在其他地方回答过此问题,请原谅(请理解,直到问完“ google”甚至“ yahooed”后,我才问)。

I am extremely new to Kahona as this framework seemed to be the best fit. 我对Kahona极为陌生,因为该框架似乎是最合适的。 I had examined somewhat Cakephp but did not care for their handling of AuthAcl - seemed a bit convoluted in that you had a 'tree' with a right and left node which I felt was unnecessarily complex. 我已经检查了Cakephp,但是并不关心他们对AuthAcl的处理-似乎有些令人费解,因为您有一棵带有左右节点的“树”,我觉得这不必要地复杂。 However, I have as yet not gotten to the AuthAcl of Kahona and may find that such an implementation is necessary. 但是,我还没有接触过Kahona的AuthAcl,可能会发现这样的实现是必要的。

There is no need for such a construct as you can easily design a self referencing ORM class. 不需要这种构造,因为您可以轻松设计自引用ORM类。 I'm not sure what you want, as the class is called Model_Article but the table has category_* columns. 我不确定您要什么,因为该类称为Model_Article但表具有category_*列。

So I will assume that you have a table categories with the given columns. 因此,我假设您有一个具有给定列的表categories Now a Model for this could look like this 现在,一个模型可能看起来像这样

class Model_Category extends ORM {
    protected $_table_name = "categories",
        $_has_many = array(
            'children' => array(
                'model' => 'Category',
                'far_key' => '__parent_id'
            )
        ),
        $_has_one = array(
            'parent' => array(
                'model' => 'Category',
                'foreign_key' => '__parent_id'
            )
        );
}

This is not tested but should at least give you the idea of the implementation. 这未经测试,但至少应该给您实现的想法。 You can always read in the documentation or the API browser on how to use what. 您始终可以在文档API浏览器中阅读有关如何使用内容的信息。 Also I would suggest playing around a bit with various settings if you feel unsatisfied. 另外,如果您不满意,我建议您在各种设置下进行测试。

If you wonder about whether to use far_key or foreign_key , this answer should help. 如果您想知道要使用far_key还是foreign_key ,那么此答案应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM