Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top