Database errors when following a tutorial.

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
reashlin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon Dec 03, 2007 11:23 am

Database errors when following a tutorial.

Post by reashlin » Mon Dec 03, 2007 1:06 pm

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.
Last edited by reashlin on Mon Dec 03, 2007 4:05 pm, edited 1 time in total.

kdevine
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: Database errors when following a tutorial.

Post by kdevine » Mon Dec 03, 2007 1:55 pm

The path to your tables directory isn't correct so JTable isn't able to find the file for your review table.

reashlin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon Dec 03, 2007 11:23 am

Re: Database errors when following a tutorial.

Post by reashlin » Mon Dec 03, 2007 2:01 pm

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
Last edited by reashlin on Mon Dec 03, 2007 2:08 pm, edited 1 time in total.

kdevine
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: Database errors when following a tutorial.

Post by kdevine » Mon Dec 03, 2007 2:09 pm

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

reashlin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon Dec 03, 2007 11:23 am

Re: Database errors when following a tutorial.

Post by reashlin » Mon Dec 03, 2007 2:16 pm

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.

kdevine
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: Database errors when following a tutorial.

Post by kdevine » Mon Dec 03, 2007 2:21 pm

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.

reashlin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon Dec 03, 2007 11:23 am

Re: Database errors when following a tutorial.

Post by reashlin » Mon Dec 03, 2007 2:26 pm

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.


Post Reply