Discussion:
Troubleshooting revIgniter library functions
Keith Clarke via use-livecode
2018-11-30 09:32:04 UTC
Permalink
Folks,
I’m struggling to get my head around revIgniter / MVC concepts and map basic LC desktop concepts to the right places in LCS + revIgniter. (I’m still searching for a 'Rosetta Stone’ to translate between these two worlds!)

My use case is to share public FAQs from specific pages designated as public in our knowledge base. I have a basic LC desktop prototype that I’m migrating to LCS + revIgniter. The desktop stack includes a single function stack script that logs into the KB server as a proxy ‘public user' and returns an access token string for subsequent page requests.

To migrate this across to the server environment, I have simply transferred the stack script into a DocLogin.lc library file, replacing the final 'return “token”’ with put tToken into gData[“doc_token”] I may have misunderstood the revIgniter docs that this is the way to get the data ‘back’ to the controller, rather than use the desktop-style function do & return to a library (or stack) file?

A DocLogin.lc controller file then attempts to call the above library and open a view file to check that the token is available via [[gData[“doc_token"] ]]

The controller is opening the view but the token merge field is not shown and adding the generic rigShowError “message” alerts that the library couldn’t be loaded.

I’d appreciate a steer as I’ve a feeling my approach here is fundamentally wrong for the LCS + revIgniter way of working.
Thanks
Keith
Andre Alves Garzia via use-livecode
2018-11-30 10:02:55 UTC
Permalink
Keith,

RevIgniter is a normal LiveCode collection of libraries. Have you read
the getting started guide at:

  https://revigniter.com/userGuide/overview/getting_started.html

It will walk you through the concepts of MVC and how they are used in
RevIgniter. Basically your models are the stuff that touch data, views
are the templates that are shown to the user and controllers are where
the business logic is. You can also have libraries. So if your DocLogin
has a function that returns a token, you can call it from a model or a
controller and get the value.

There is really no "1 minute explanation" that will clear it all,
RevIgniter is quite easy and consistent but it requires you to go over
its documentation at least once. Some URLs of interest are:

  https://revigniter.com/userGuide/overview/appflow.html

  https://revigniter.com/userGuide/tutorials/chat.html

I recommend doing the tutorial a lot.

Cheers

andre
Post by Keith Clarke via use-livecode
Folks,
I’m struggling to get my head around revIgniter / MVC concepts and map basic LC desktop concepts to the right places in LCS + revIgniter. (I’m still searching for a 'Rosetta Stone’ to translate between these two worlds!)
My use case is to share public FAQs from specific pages designated as public in our knowledge base. I have a basic LC desktop prototype that I’m migrating to LCS + revIgniter. The desktop stack includes a single function stack script that logs into the KB server as a proxy ‘public user' and returns an access token string for subsequent page requests.
To migrate this across to the server environment, I have simply transferred the stack script into a DocLogin.lc library file, replacing the final 'return “token”’ with put tToken into gData[“doc_token”] I may have misunderstood the revIgniter docs that this is the way to get the data ‘back’ to the controller, rather than use the desktop-style function do & return to a library (or stack) file?
A DocLogin.lc controller file then attempts to call the above library and open a view file to check that the token is available via [[gData[“doc_token"] ]]
The controller is opening the view but the token merge field is not shown and adding the generic rigShowError “message” alerts that the library couldn’t be loaded.
I’d appreciate a steer as I’ve a feeling my approach here is fundamentally wrong for the LCS + revIgniter way of working.
Thanks
Keith
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Ralf Bitter via use-livecode
2018-11-30 12:37:02 UTC
Permalink
Hi Keith,

in addition to Andre’s valuable tips I would like
to comment that your approach should actually work,
but be advised to make sure you include your custom
library as described here:

https://revigniter.com/userGuide/general/creating_libraries.html

Furthermore you can leave your function as is i.e.
call your library function within your DocLogin.lc controller like:

put myDocLoginHandler() into gData["doc_token"]

For debugging purposes make sure the logs folder is writable,
set the gConfig["logThreshold"] in config.lc to 4 and check the
log file in case something goes wrong.


Ralf
Post by Keith Clarke via use-livecode
Folks,
I’m struggling to get my head around revIgniter / MVC concepts and map basic LC desktop concepts to the right places in LCS + revIgniter. (I’m still searching for a 'Rosetta Stone’ to translate between these two worlds!)
My use case is to share public FAQs from specific pages designated as public in our knowledge base. I have a basic LC desktop prototype that I’m migrating to LCS + revIgniter. The desktop stack includes a single function stack script that logs into the KB server as a proxy ‘public user' and returns an access token string for subsequent page requests.
To migrate this across to the server environment, I have simply transferred the stack script into a DocLogin.lc library file, replacing the final 'return “token”’ with put tToken into gData[“doc_token”] I may have misunderstood the revIgniter docs that this is the way to get the data ‘back’ to the controller, rather than use the desktop-style function do & return to a library (or stack) file?
A DocLogin.lc controller file then attempts to call the above library and open a view file to check that the token is available via [[gData[“doc_token"] ]]
The controller is opening the view but the token merge field is not shown and adding the generic rigShowError “message” alerts that the library couldn’t be loaded.
I’d appreciate a steer as I’ve a feeling my approach here is fundamentally wrong for the LCS + revIgniter way of working.
Thanks
Keith
Keith Clarke via use-livecode
2018-11-30 14:23:01 UTC
Permalink
Thanks Ralf (& Andre) for the responses.

I have read the user guide and understood more than I expected, given my basic HTML + jQuery + CSS background! I’ve also been learning more as I build my app out using user guide worked examples where they exist.

Thanks for the syntax for processing the response returned from the library - I know understand the central role of the controller page and how that call & response should work.

Thanks also for the tip regarding the log, as that has proven more revealing… errors when attempting to load library files into any controllers.

Stripping back to basics, I have created a testLib.lc library file in the default system/application/libraries folder that contains just the prototype markup from the user guide.

My default controller is home.lc (copied from welcome.lc) which throws an error "Unable to load the requested library:Testlib” if I add 'rigLoaderLoadLibrary “testLib” ‘ to the home or index handler markup.

Any clues as to what I may have missed?
Thanks
Keith
Post by Ralf Bitter via use-livecode
Hi Keith,
in addition to Andre’s valuable tips I would like
to comment that your approach should actually work,
but be advised to make sure you include your custom
https://revigniter.com/userGuide/general/creating_libraries.html
Furthermore you can leave your function as is i.e.
put myDocLoginHandler() into gData["doc_token"]
For debugging purposes make sure the logs folder is writable,
set the gConfig["logThreshold"] in config.lc to 4 and check the
log file in case something goes wrong.
Ralf
Post by Keith Clarke via use-livecode
Folks,
I’m struggling to get my head around revIgniter / MVC concepts and map basic LC desktop concepts to the right places in LCS + revIgniter. (I’m still searching for a 'Rosetta Stone’ to translate between these two worlds!)
My use case is to share public FAQs from specific pages designated as public in our knowledge base. I have a basic LC desktop prototype that I’m migrating to LCS + revIgniter. The desktop stack includes a single function stack script that logs into the KB server as a proxy ‘public user' and returns an access token string for subsequent page requests.
To migrate this across to the server environment, I have simply transferred the stack script into a DocLogin.lc library file, replacing the final 'return “token”’ with put tToken into gData[“doc_token”] I may have misunderstood the revIgniter docs that this is the way to get the data ‘back’ to the controller, rather than use the desktop-style function do & return to a library (or stack) file?
A DocLogin.lc controller file then attempts to call the above library and open a view file to check that the token is available via [[gData[“doc_token"] ]]
The controller is opening the view but the token merge field is not shown and adding the generic rigShowError “message” alerts that the library couldn’t be loaded.
I’d appreciate a steer as I’ve a feeling my approach here is fundamentally wrong for the LCS + revIgniter way of working.
Thanks
Keith
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Ralf Bitter via use-livecode
2018-11-30 16:14:20 UTC
Permalink
Hi Keith,

if you change the name of your library to Testlib.lc
and if you adjust the name in your controller respectively
all should work as expected.
There is a naming convention for library files, i.e.
camel case is not allowed, but it seems this is not
mentioned in the user guide.
Sorry for the hassle. Will fix that.


Ralf
Post by Keith Clarke via use-livecode
Thanks Ralf (& Andre) for the responses.
I have read the user guide and understood more than I expected, given my basic HTML + jQuery + CSS background! I’ve also been learning more as I build my app out using user guide worked examples where they exist.
Thanks for the syntax for processing the response returned from the library - I know understand the central role of the controller page and how that call & response should work.
Thanks also for the tip regarding the log, as that has proven more revealing… errors when attempting to load library files into any controllers.
Stripping back to basics, I have created a testLib.lc library file in the default system/application/libraries folder that contains just the prototype markup from the user guide.
My default controller is home.lc (copied from welcome.lc) which throws an error "Unable to load the requested library:Testlib” if I add 'rigLoaderLoadLibrary “testLib” ‘ to the home or index handler markup.
Any clues as to what I may have missed?
Thanks
Keith
Keith Clarke via use-livecode
2018-11-30 17:26:54 UTC
Permalink
Thanks Ralf. Renaming the library got past that library load error. However, the view page is listing other errors, which may hint at other mistakes I’ve made.

The key page markup is below - I’d appreciate any advice.

**********************************************

The testlib.lc library content is just the prototype with a “Hello World” test return in the example handler...

<?rev
put gBASEPATH into gBASEPATH

if gBASEPATH is "gBASEPATH" then
put "No direct script access allowed."
exit to top
end if

# LOGGING
rigLogMessage "debug", "Your Library Loaded"

# DECLARE LOCAL VARIABLES


# PROTOTYPE OF THE FOLLOWING HANDLER NAME: rigRunInitialLibrarynameConfig
command rigRunInitialYourlibConfig
--Run initial configuration procedures. Don't remove this handler, even if it does nothing.
end rigRunInitialYourlibConfig

command someHandler
return "Hello World"
end someHandler

************************************************

The home.lc controller seeks to load the testlib library & add the "Hello World" return value to the global data array…

<?rev

# PUT ALL HANDLER NAMES WHICH ARE LIKELY TO SERVE AS URI SEGMENTS
# INTO THE GLOBAL gControllerHandlers AS A COMMA SEPARATED LIST
put "home,index" into gControllerHandlers

# WRITE INITIAL STATEMENTS INTO THE CONTROLLER HANDLER
command home
# SAVE PAGE IN CACHE DIRECTORY WITH AN EXPIRATION TIME OF n MINUTES
# NOTE: THIS IS NOT MANDATORY, DON'T USE CACHING WHILE WORKING ON THE CODE,
# OTHERWISE YOU WON'T SEE YOUR CHANGES IMMEDIATELY
rigOutputCache 3
rigLoaderLoadLibrary "testlib"
put somehandler() into gData["testlib"]
end home

# THIS COMMAND WILL BE CALLED IF NONE IS SPECIFIED IN THE URI
command index
# REMEMBER TO PUT ALL THE VARIABLES TO BE MERGED WITH VIEWS INTO THE ARRAY VARIABLE gData
# SET PAGE TITLE
put "Welcome to the Knowledge Base" into gData["pageTitle"]

put RIVERSION && RISTATE into gData["revIgniterVersion"]
put the version into gData["serverVersion"]

# LOAD THE VIEW FILE
get rigLoadView("home")
end index

****************************************

The home view is a copy of the welcome.lc view with one line added to show the "Hello World” test

<p>[[gData["testlib"] ]]</p>

****************************************

The inline error list override of the view page may provide some clues (paths truncated with ‘…' ) ...
file “/.../system/application/config/autoload.lc"
file “/.../system/libraries/Controller.lc"
file “/.../system/libraries/Loader.lc"
file “/.../system/libraries/Language.lc"
file “/.../system/libraries/Output.lc"
file “/.../system/application/config/routes.lc"
file “/.../system/libraries/Input.lc"
file “/.../system/libraries/Router.lc"
file “/.../system/libraries/Config.lc"
file “/.../system/libraries/URI.lc"
file “/.../system/libraries/Log.lc"
file “/.../system/libraries/Hooks.lc"
file “/.../system/libraries/Benchmark.lc"
file “/.../system/application/config/config.lc"
file “/.../system/revigniter/Common.lc"
file “/.../system/application/config/constants.lc"
file “/.../system/revigniter/RevIgniter.lc"
file “/.../index.lc"
file “/.../system/application/config/config.lc"
row 1822, col 1: Handler: can't find handler (rigRunInitialtestlibConfig)
row 1823, col 1: do: error in statement (rigRunInitialtestlibConfig "")
row 1823, col 1: if-then: error in statement
row 1819, col 1: Handler: error in statement (_rigRiInitLibrary)
row 1284, col 1: Handler: can't find handler (_rigRiInitLibrary)
row 1284, col 1: repeat: error in statement
row 1284, col 1: repeat: error in statement
row 1187, col 1: Handler: error in statement (_rigLoadLibrary)
row 106, col 1: Handler: can't find handler (_rigLoadLibrary)
row 106, col 1: if-then: error in statement
row 106, col 1: if-then: error in statement
row 95, col 1: Handler: error in statement (rigLoaderLoadLibrary)
file “/.../system/revigniter/RevIgniter.lc"
row 13, col 1: Handler: can't find handler (rigLoaderLoadLibrary)
row 13, col 1: Handler: error in statement (home)
file “/.../system/application/controllers/home.lc"
row 399, col 1: Handler: can't find handler (home)
row 400, col 1: do: error in statement (home)
row 400, col 1: if-then: error in statement
row 400, col 1: if-then: error in statement
row 387, col 1: Handler: error in statement (_rigDo)
row 273, col 1: Handler: can't find handler (_rigDo)
file “/.../system/application/libraries/testlib.lc"
Best,
Keith
Post by Ralf Bitter via use-livecode
Hi Keith,
if you change the name of your library to Testlib.lc
and if you adjust the name in your controller respectively
all should work as expected.
There is a naming convention for library files, i.e.
camel case is not allowed, but it seems this is not
mentioned in the user guide.
Sorry for the hassle. Will fix that.
Ralf
Post by Keith Clarke via use-livecode
Thanks Ralf (& Andre) for the responses.
I have read the user guide and understood more than I expected, given my basic HTML + jQuery + CSS background! I’ve also been learning more as I build my app out using user guide worked examples where they exist.
Thanks for the syntax for processing the response returned from the library - I know understand the central role of the controller page and how that call & response should work.
Thanks also for the tip regarding the log, as that has proven more revealing… errors when attempting to load library files into any controllers.
Stripping back to basics, I have created a testLib.lc library file in the default system/application/libraries folder that contains just the prototype markup from the user guide.
My default controller is home.lc (copied from welcome.lc) which throws an error "Unable to load the requested library:Testlib” if I add 'rigLoaderLoadLibrary “testLib” ‘ to the home or index handler markup.
Any clues as to what I may have missed?
Thanks
Keith
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Ralf Bitter via use-livecode
2018-11-30 22:56:17 UTC
Permalink
Hi Keith,

seems that you have overlooked that your library
handler is not a function, see line

put somehandler() into gData["testlib"]

in your controller.

Furthermore don’t forget to adjust the name of your library
initialisation handler to “rigRunInitialteslibConfig”.


Ralf
Post by Keith Clarke via use-livecode
Thanks Ralf. Renaming the library got past that library load error. However, the view page is listing other errors, which may hint at other mistakes I’ve made.
The key page markup is below - I’d appreciate any advice.
Keith Clarke via use-livecode
2018-11-30 23:52:54 UTC
Permalink
Brilliant - thanks for the analysis and syntax corrections, Ralf.

That’s clarified more of the LCS / MVC ‘plumbing' and provided a worked example I can repeat as I start to build-out the app proper.

Much appreciated
Best,
Keith
Post by Ralf Bitter via use-livecode
Hi Keith,
seems that you have overlooked that your library
handler is not a function, see line
put somehandler() into gData["testlib"]
in your controller.
Furthermore don’t forget to adjust the name of your library
initialisation handler to “rigRunInitialteslibConfig”.
Ralf
Post by Keith Clarke via use-livecode
Thanks Ralf. Renaming the library got past that library load error. However, the view page is listing other errors, which may hint at other mistakes I’ve made.
The key page markup is below - I’d appreciate any advice.
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...