I was trying to integrate jQuery to use it for some effects in my site and I started to search for the solution of integrating in the best way. It simply came to my mind to write a helper which would get the selector of proper element and output the javascript code.
Then I ran into the new JsHelper in cake 1.3 but I'm really having problems understanding the concept of JsHelper. I mean for sure each JavaScript block that I'm gonna write is more than one call to jQuery methods and many of them are also not transfered to JsHelper. So for what reason may I use the JsHelper? it would be much easier to write the javascript specified for my action inside a helper and use it simply as any other helper. The only thing which comes to my mind as a good capability is to use the caching and buffering options provided in JsHelper nothing more. Did I understood the JsHelper well or I have missed some points?
FWIW, I never use any of the javascript helpers except to write the include, i.e.
<?php echo $javascript->link('aJavascriptFile') ?>
I'd be pulling my hair out trying to find out why some jQuery plugin wasn't working if it was all wrapped up in helpers.
You don't have to use helpers - they're there to help. Sometimes people go a bit crazy and start creating helpers for stuff that really doesn't justify the weight of extra code.
Just code it the 'old way' and keep your sanity.
Related
I have been thinking implementing translation for my app and I have the following idea
Make the English and My language [Amharic] mirror jsons and render English if selected. Just configuration Json file from the server that gets called once app routed
Make all in one API to get the json once and persist
will it be a good idea,How is this implemented on real world
Don't need to implement it yourself. angular-translate is an excellent module, here you can take a look at it: https://angular-translate.github.io/ .It covers everything you need.
It is plenty of features and some of them are:
Flexibility
Pluralization
Directive
Filter
Service
Asynchronous loading
Keep in mind that this module has been there for a long time and many people use it. You can solve everything you need and there is no need to reinvent the wheel.
Is there any way to auto-generate Swagger documentation (or similar) for a Nancy service?
I found Nancy.Swagger, but there's no information on how to use it and the demo application doesn't seem to demonstrate generating documentation (if it does, it's not obvious).
Any help would be appreciated. Thanks!
In my current project I've been looking a lot into this problem. I used both nancy.swagger and nancy.swagger.attributes.
I quickly discarded Nancy.swagger, because for me personally it doesn't sound right that you have to create a pure documentation class for each nancy module. The attributes solution was a bit "cleaner" - at least codebase and documentation were in one place. But very fast this became unmaintainable. Module code is unreadable because of many attributes. Nothing is generated automatically: you have to put path, all parameters, even http method as an attribute. This is a huge effort duplication. Problems came very fast, a few examples:
I changed POST to PUT in Nancy and forgot to update [Method] attribute.
I added a parameter but not the attribute for it.
I changed parameter from path to query and didn't update the attribute.
It's too easy to forget to update the attributes (let alone documentation module solution), which leads to discrepancies between your documentation and actual code base. Our UI team is in another country and they had some trouble using the APIs because docu just wasn't up-to-date.
My solution? Don't mix code and documentation. Generating docu from code (like Swashbuckle does) IS ok, but actually writing docu in code and try to dublicate the code in docu is NOT. It's not better than writing it in a Word document for your clients.
If you want Swagger docu, just do it the Swagger way.
- Spend some time with Swagger.Editor and really author your API in
YAML. It looks all-text and hard, but once you get used to it, it's
not.
- Spend some time with Swagger.Codegen and adapt it (it already does a fair job for generating Nancy server code and with a few
adjustments to moustache templates it was just what I needed).
- Automate your process: write a couple of batches to generate your modules and models from yaml and copy them to your repository.
Benefits? Quite a few:
-
Your YAML definition is now the single truth of your REST contract.
If somewhere something is defferent, it's wrong.
Nancy server code is auto-generated
Client code-bases are auto-generated (in our case it's android, ios and angular)
So whenever I change something in REST contract, all codebases are regenerated and added to projects in one batch. I just have to tell the teams something was updated. They don't have to look through some documents and search for it. They just have their code regenerated and probably see some compile errors, in case of breaking changes.
Do I still use nancy.swagger(.annotations)?
Yes, I do use it in another project, which has just one endpoint with a couple of methods. They don't change often. It's not worth the effort to set up everything, I have my swagger docu fast up and running. But if your project is big, API is changing, and you have multiple code-bases depending on your API, my advice is to invest some time into a real swagger setup.
I am quoting the author answer here from https://github.com/khellang/Nancy.Swagger/issues/59
The installation should be really simple, just pull down the NuGet package, add metadata modules to describe your routes, and hit /api-docs. That should get you the JSON. If you want to add swagger-ui as well, you have to add that manually right now.
No. Not in an automated. https://github.com/yahehe/Nancy.Swagger needs lots of manually created metadata.
There is a nice article here: http://www.c-sharpcorner.com/article/generating-api-document-in-nancy-using-swagger/
Looks like you still have to add swagger-ui separately.
I am needing to integrate Sage Pay on our website to accept online payments.
I have downloaded and tested the PHP kit provided by Sage and have run a few successful tests, however, I don't know where to start when it comes to integrating this with Cake PHP.
If anybody has some initial pointers or ideas, or even links (multiple, varied Google searches yielded nothing) that would be great ...
Many thanks,
Dave
Hi there,thanks for the reply, and apologies for the delayed replying myself. I have it all working now, except my final issue as that I need to parse the final response returned from SagePay. The demo has the following code in the final step that gets posted to my site (to an action), The code they have is as follows:
...
$strVPSSignature=$_REQUEST["VPSSignature"];
$strStatusDetail=$_REQUEST["StatusDetail"];
...
Obviously this won't work due to Cake's routing. How do you suggest I parse these value>
Thanks again.
Dave
Haven't used Sagepay but a few pointers anyway:
Third party PHP classes should be loaded as vendors, so that is what I would do with their PHP kit.
This guy thinks SagePay's kit is a mess so you might find using his classes is easier to grok.
Although some might say payments belong in the business layer (your model), you might find it easier to initially perform payments from the controller layer. As such, I would start by creating a simple component with the inputs and outputs you need (methods/parameters/return values) and use it as a wrapper for the SagePay vendor of your choice. This will help keep your controller actions skinny. You can refactor later to your taste once you get things working.
i have something here that is basically from jqueryui. Yes, it is raw and the example uses JSON to handle the autocompleting process. My back end developers are using python on GAE and they usually just draw data out from the gql direct and dump it into the webpage. i need this function to create tags just like stackoverflow. What is the best practice in my situation here?
Whiff includes support for both GAE, jqueryUI, and AJAX that works really well for me. Have a look at http://whiffdoc.appspot.com -- particularly the tutorials.
If I am using CAKEphp do I need to use smartytemplates too?
No.
Cake has its "own" templating system which uses .ctp files, which are just straight HTML/PHP files.
You can integrate pretty much anything with Cake, including Smarty. When I first started, I thought about doing it and my advice is don't. You just don't need to. Cake's own templating system is fully featured and comes with a lot of helpers, integration, convention etc. (not to mention online wisdom).
Having another template system will only make life complicated. Apart from that, think of the practicalities of pushing two codebases around, maintaining them and wearing different hats depending on which part you're working on.
CakePHP is delivered with all you need to build most web applications.
Not necessary. The smarty templates are optional, if you wish you can use them or leave them.