Knop usage - database

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Knop usage - database

Johan Solve-2
I thought it could be interesting to see some simple usage cases, as inspiration and to help understanding Knop. I'll begin with an example to output some fields from a specific database record, using the database type.


// initiate the database object (normally in a config file)
var: 'db_news'=(knop_database: -database='acme', -table='news',
        -username='knopuser', -password='knopuser',
        -keyfield='id');


// perform a database search to grab the record (normally in a lib file)
$db_news -> (getrecord: -keyvalue=185);


// show some fields from the database record (normally in a content file)
<h3>[$db_news -> (field: 'title')] </h3>
<p>
[encode_break: ($db_news -> (field: 'text'))]
</p>

----

// The getrecord statement can be simplified slightly since the first parameter is the keyvalue
$db_news -> (getrecord: 185);


// If a more complex query is needed to get the record, select can be used instead.
// The data from the first found record will be available as ->field
// (not in the current version, but in the next update).
$db_news -> (select: -sql='SELECT * FROM news LEFT JOIN ...');



--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Knop usage - database

Johan Solve-2
At 16.51 +0100 2007-04-18, Ric Lewis wrote:
>Johan
>
>I haven't looked at my knop test site for over a week, but I remember having an issue where when using an SQL statement (and hence Inlinename) I couldn't get it to pass the keyvalue to the knop_grid listing for the edit links. Of course it could be achieved now with a compound expression instead of using the -url parameter, but that seems overkill. Using a standard inline on the same page passed the keyvalue, as expected.

A problem with SQL inlines is that Knop has very little control over what's happening. For example if the keyfield is not included as column in the SELECT statement, there is no way for Knop to get the keyvalue. Could your problem be caused by omitting the keyfield from the column specification in the SQL SELECT?

>One other observation from my experiments - unless I missed it completely, knop doesn't have a 'detail' page, as such, when you view a record, you'd always be in edit mode. Again, detail pages can be created manually, but this is such a common requirement and has a lot of crossover with the form type, that it would seem logical to have as an option in the framework.

The form type has ->renderhtml which can be used exactly for this purpose. It is actually intended (more or less consciously) for displaying data on a detail page.

So get a record using the database type, define a form, fill the form with data from the query and display the data using ->renderhtml (after setting a proper html template if the default simple template '#label#: #field#<br>\n' isn't suitable).

Example code:
var: 'form_news'=(knop_form: ...
        -database=$db_news);
$db_news -> (getrecord: 185);
$form_news -> (loadfields: -database); // this is a new shorter way to write it (not in the current version either...)

// variant if we have no database defined for the form, or if we want to override that:
$form_news -> (loadfields: -database=$db_products);


// Old way:
$form_news -> (loadfields: -inlinename=($db_news -> inlinename));

--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Knop usage - database

Ric Lewis-3
I thought about that, so I tried various options in the SELECT. The  
keyfield is coming though fine, it displays in the grid, but it seems  
it's not available to the -url routine to create the nice edit links:

http://my.dev.site/admin/teams/edit/j5izzfiyke6p1/

instead you get:

http://my.dev.site/admin/teams/edit//

Looking at the knop_grid ctype I don't think it's currently supported  
when you go the SQL -inlinename route.

Cheers

Ric


On 18 Apr 2007, at 19:27, Johan Solve wrote:

> A problem with SQL inlines is that Knop has very little control  
> over what's happening. For example if the keyfield is not included  
> as column in the SELECT statement, there is no way for Knop to get  
> the keyvalue. Could your problem be caused by omitting the keyfield  
> from the column specification in the SQL SELECT?


#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Knop usage - database

Johan Solve-2
It sounds like you don't have a nav object attached to the grid. That's a requirement to get the nice "automatic" edit links because otherwise Knop doesn't know how to assemble the url.
If you don't have a nav object for the grid you would have to craft the url yourself (instead of just passing a nav path for -url), like in the mailto example in cfg_advanced_list.inc in the Knop example (the handling of -url when there is no nav object connected to the grid is far from ideal, I admit).
For example -url='/admin/teams/edit/#value#'
However, that would show the keyvalue as link text which is not very nice so you would be better of using -template with a compound expression to create that edit link.

But again, if you have a nav object connected to the grid object then it should all just work, regardless of if you have an sql query or standard lasso inline query, as long as the keyfield is available in the result.
This is how the keyvalue is grabbed inside an inlinename records loop:
                                #output += '<a href="' + (#nav -> (url: -path=#url,
                                        #keyparamname=(field: #keyfield),

Well, as long as the inlinename you specify matches the database and table secified in the database object that is connected to the grid object (or at least the keyfield in your inlinename search is the same as for the database object). The #keyfield variable above comes from the database object so if that doesn't match what you consider as the keyfield in your query then the keyvalue is lost.
Btw I might have missed if you use the database object to perform the database query, or if you use your own inline.


At 09.57 +0100 2007-04-19, Ric Lewis wrote:

>I thought about that, so I tried various options in the SELECT. The keyfield is coming though fine, it displays in the grid, but it seems it's not available to the -url routine to create the nice edit links:
>
>http://my.dev.site/admin/teams/edit/j5izzfiyke6p1/
>
>instead you get:
>
>http://my.dev.site/admin/teams/edit//
>
>Looking at the knop_grid ctype I don't think it's currently supported when you go the SQL -inlinename route.
>
>Cheers
>
>Ric
>
>
>On 18 Apr 2007, at 19:27, Johan Solve wrote:
>
>>A problem with SQL inlines is that Knop has very little control over what's happening. For example if the keyfield is not included as column in the SELECT statement, there is no way for Knop to get the keyvalue. Could your problem be caused by omitting the keyfield from the column specification in the SQL SELECT?
>
>
>#############################################################
>This message is sent to you because you are subscribed to
>the mailing list <[hidden email]>.
>To unsubscribe, E-mail to: <[hidden email]>
>Send administrative queries to  <[hidden email]>
>List archive http://lists.montania.se/Lists/knop/
>(log in with your email and ConfirmationID as password, send message to
><[hidden email]> to get that ID)
>Project homepage http://montania.se/projects/knop/
>AIM chatroom knop aim:gochat?roomname=knop


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop

Loading...