Page 1 of 1

Database errors when following a tutorial.

Posted: Mon Dec 03, 2007 1:06 pm
by reashlin
Hey,

I am following a tutorial document which shows me how to build a "restuarant review" component.  This is useful as the site I am currently working on requires this.

However while following the tutorial I have an error come up on one of my pages "Table Review not supported. File not found."

I can post detailed code if it is required but this is what I can see is going on from my perspective.

Code: Select all

<?php
    defined( '_JEXEC' ) or die( 'Restricted access' );
    require_once( JApplicationHelper::getPath( 'admin_html') );
    JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');
    // Some code for a switch statement.
    }
    function editReview( $option ) {
        $row =& JTable::getInstance('Review', 'Table');

This is the code I am using to first reference my database and I feel it is here the error is.  Given that my table is called jos_review_data what should this line read.

I have also created a sub directory and file tables/reviews.php which contains the following.

Code: Select all

<?php
    defined( '_JEXEC' ) or die( 'Restricted access' );
    class TableReview extends JTable {
        var $id = null;
        var $submitted_by = null;
        var $hotel_being_reviewed = null;
        var $text = null;
        var $average_rating = null;
       
        function __construct(&$db) {
            parent::__construct( '#__reviews_data', 'id', $db );
        }
    }
?>

Looking at this it looks all ok to me.  But it could be useful should the problem be here.

Re: Database errors when following a tutorial.

Posted: Mon Dec 03, 2007 1:55 pm
by kdevine
The path to your tables directory isn't correct so JTable isn't able to find the file for your review table.

Re: Database errors when following a tutorial.

Posted: Mon Dec 03, 2007 2:01 pm
by reashlin
I had guessed that was what was happening (or not happening) but I cant see why the path is incorrect.  Can anyone see in my code where the path is wrong.  Is there other code I should have that I can post for help.

edit:

Are you saying  \/ is incorrect.

Code: Select all

JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');


If this is the case then does anyone know what the code should be.  I will continue to poke this until something happens.

Cheers

Re: Database errors when following a tutorial.

Posted: Mon Dec 03, 2007 2:09 pm
by kdevine
echo that path in your code and check if it's right. One reason it could be wrong is that the file your trying to set the path with is in administrator/components/com_component but the table directory is in components/com_component.

One other reason for this error is that you don't actually have a file in your tables directory named review.php

Re: Database errors when following a tutorial.

Posted: Mon Dec 03, 2007 2:16 pm
by reashlin
Cheers,

Changing the file name from reviews.php to review.php (note the dropping of the 's') has helped.  Do you know where it is I have specified the filename wrong as I have always refered to this component by the title reviews.

Cheers for the excellent help.

Re: Database errors when following a tutorial.

Posted: Mon Dec 03, 2007 2:21 pm
by kdevine
You can keep the file named reviews.php if you want but then you have to change the classname to TableReviews and the JTable::getInstance needs to call Reviews.

Re: Database errors when following a tutorial.

Posted: Mon Dec 03, 2007 2:26 pm
by reashlin
Thanks,

All sorted now and I understand what I did wrong.  This forum needs some form of credit system like the sun.java.com forums do.  Bonus credit is added for people who respond in a positive way.

Anyway, thanks again.