Neko workflow and Ajax

82 views
Skip to first unread message

michael solomon

unread,
Jul 16, 2015, 6:29:10 PM7/16/15
to haxe...@googlegroups.com
Hi,
I'm trying to create a simple FAQ system (for learning purposes - so I don't want to use external libraries), I need some advices about best practices on work with Neko:
Now, I created a Neko project and built a simple website, HTML files rendered by haxe.Template, I learned by this guide.
  1. Correct me if I wrong but I shouldn't have any .html file in my work tree. all of them will create by nekoVM in runtime?
  2. In php for each page in website you need a php file, neko it's binary, how I can create a "new" page? 2 neko files? how the routing system work?

Any guide or tutorial on this subject would appreciate, In addition if you have some recommendations and advices I would be happy to listen :)


And Ajax:

I can easily write a Ajax js in my template(haxe.Template) but how I handle with this Ajax in server side? (it's very similar to number 2 above..)


THanks you very much!
Michael

Rafael Oliveira

unread,
Jul 16, 2015, 8:16:57 PM7/16/15
to haxe...@googlegroups.com
For neko and php, you don't need to have any html or php files. Now that you are rendering the templates, you can use the Web dispatcher to route to differents templates:


The template tutorial suggest you to save the template as a resource, if you don't want to specify all the files in the hxml, you can use this class to load the file from the system:

sys.io.File.getContent('templates/template.mtt');

as for ajax, you can use haxe.http and haxe remote

Michel Romecki

unread,
Jul 17, 2015, 9:17:36 AM7/17/15
to haxe...@googlegroups.com
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

michael solomon

unread,
Jul 18, 2015, 2:30:26 PM7/18/15
to haxe...@googlegroups.com
Thanks guys..
  1. in "-d" attribute for Neko server tools I should put the Neko file or my root folder? i.e: nekotools server -p 2000 -h localhost -d .\bin -rewrite or nekotools server -p 2000 -h localhost -d .\bin\myneko.n -rewrite
  2. In Dispatch.run, I should do it for each path or once for root path and put all paths in my controller? i.e: like this or this

Rafael Oliveira

unread,
Jul 19, 2015, 1:01:10 AM7/19/15
to haxe...@googlegroups.com
from my experience, change the name of your main file to Index.hx (and the name of the class to Index), compile to index.n
then enter in the folder where the neko is, and just use

nekotools server -rewrite

and it will be served in the port 2000. I don't know about the -d option, but this is simpler to use.

About the Dispatch.run, use only one pointing to the root controler, because Request.getURI() will get the path you requested and will choose the right function in the controler. with the path hardcoded like this

Dispatch.run("/user", null, new Controller());
Dispatch.run("/default", null, new Controller());

you will not be able to go to different pages, it will always call the function for the 'user' page. the page will be sent to the browser, and the second command will not be called.

from the root controler you can have a function that will sub dispatch to another path in your website. eg. if you have a api in www.webpage.com/api, in the root controler you can use

public function doApi(d:Dispatch)
{
d.dispatch(new controllers.Api());

this way you can use another controller just for the api functions.

michael solomon

unread,
Jul 19, 2015, 1:44:57 AM7/19/15
to haxe...@googlegroups.com
Thank you very much! That was very helpful.
Reply all
Reply to author
Forward
0 new messages