This topic is locked
[SOLVED]

Using custom view in another query on another page.

6/30/2024 3:10:32 AM
PHPRunner General questions
C
Chris Whitehead author

I know that the custom views aren't the same as a view which I create in a database.

The custom views are able to be used in the lookup, I was wondering if there's a way to access them elsewhere, for example in an external page.

The reason I'm asking is the custom view is using a session variable and rather than put a view in the database and then tag on the condition with the session in the page, it would be helpful. to hijack the custom view query.

It also means if I add a field alias then I'm only changing within the PHPRunner eviroment rather than updating the database view.

Is this possible or am I limited to only using database views for external pages?

Sergey Kornilov admin 7/1/2024

Custom View is a just a SQL query. I'm not sure what prevents you from using this SQL query on another page.

C
Chris Whitehead author 7/1/2024

@Sergey Kornilov Yes, I could just copy and paste to use the query where I need it.

It just struck me that a custom view is accessible in the lookup_wizard in the designer page and it would be useful to have the query in one place (the custom view), then reuse it in other areas, if I want add another field or filter, join another table etc, I only have to update it in one place rather than remember everywhere I copied the query..

I just wondered if it could be accessesed via the database API, I'm guessing it's a no, if no then is the custom view I see in the lookup wizard just a copy of the query from the view?

// requesters is a custom view in the project
$data -array( "business_id" => 1 );
$rs = DB::Select("requesters", $data );
while( $record = $rs->fetchAssoc() ) {
Sergey Kornilov admin 7/1/2024

Database API works directly with databases and Custom View is an entity defined in PHPRunner. Simply doesn't work this way. If you need something reusable than database view is a way to go.

C
Chris Whitehead author 7/2/2024

Sergey, Thanks for clearing that up, I'll split them and have the same view in the DB as well as the custom view, worst case it will only be 2 places to update.