Unable to add new record

A place for users and developers of the Xataface to discuss and receive support.

Re: Unable to add new record

Postby TBriggs » Thu Jun 30, 2011 3:24 pm

PHP4 is what my hosting company loads by default. I've got 3 databases on this web site, all using a Xataface front end and I'm scared of breaking anything!
TBriggs
 
Posts: 47
Joined: Mon Mar 02, 2009 6:38 am
Location: Gulfport, FL

Re: Unable to add new record

Postby TBriggs » Sat Jul 02, 2011 12:31 pm

To be honest, I don't know where that code in the index.php file came from! I thought Xataface put it in there all by itself.

I actually have another problem with this file. The interface was originally only accessing one table in the database, but now I've allowed access to another table. Unfortunately, it looks like Xataface is trying to enforce these sort rules to the other table, which doesn't have the same fields. How do I make this piece of code only apply to the "greyhounds" table?

Thanks.
TBriggs
 
Posts: 47
Joined: Mon Mar 02, 2009 6:38 am
Location: Gulfport, FL

Re: Unable to add new record

Postby TBriggs » Sun Jul 03, 2011 12:57 pm

Ah - I found the answer in another thread. This appears to work:

Code: Select all
if ( !$_POST and !isset($_GET['-sort']) and @$_REQUEST['-table'] == 'greyhounds' ){
    $_GET['-sort'] = $_REQUEST['-sort'] = 'dog_name asc';
}
TBriggs
 
Posts: 47
Joined: Mon Mar 02, 2009 6:38 am
Location: Gulfport, FL

Re: Unable to add new record

Postby shannah » Sun Jul 03, 2011 1:32 pm

The best way is actually to put this inside the beforeHandleRequest() method of the application delegate class, and to use the query as returned from Dataface_Application::getQuery() because that way it guarantees that the -table parameter has been set.

e.g.
Code: Select all
function beforeHandleRequest(){
    $query =& Dataface_Application::getInstance()->getQuery();
    if ( !$_POST and $query['-table'] == 'foo' and !@$query['-sort'] ){
        $query['-sort'] = 'bar desc';
    }
}


*This code only works in PHP 5 or higher due to chaining.
**It is important to return the query by reference (i.e. =&) so that you can affect the query in place.

Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Unable to add new record

Postby TBriggs » Thu Jul 07, 2011 4:40 pm

I've just noticed another issue with this installation. When I first log in to the database, the greyhounds table displays in list mode, but it's not sorted. If I go to another screen and then go back to the list, it's sorted by dog_name like it should be.

Any idea why it isn't sorted the first time in?

Thanks,
TBriggs
 
Posts: 47
Joined: Mon Mar 02, 2009 6:38 am
Location: Gulfport, FL

Previous

Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 12 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved