How to create basic pages with Symfony and Doctrine - database

I'm completely new with Symfony and Doctrine. I have generated a project with a the Doctrine ORM, my database schema is fully well generated.
Now I just want to create basic services (in simple .php pages) that do some actions according to parameters in a HTTP POST request.
I tried to create an app through the generate:app command but it seems to be a really ugly way...
I just need a basic .php page where I can use my doctrine objects and interact with my database easly. What is the easiest way to do that (can I do that with some basic require_once or I need to generate something with symfony, like a module ?) ?
Thank you!

I think symfony might not be for you. There is a 'symfony-way' of doing things. Part of that is the MVC seperation of logic.
A simple page would be:
$ ./symfony generate:project yourprojectname
$ ./symfony configure:database "mysql:host=localhost;dbname=yourdbname" root yourpassword
$ ./symfony generate:app frontend
$ ./symfony generate:module frontend yourmodule
Ok, now you have a module. Go to localhost/web/frontend_dev.php/module and you will see that you have setup a basic module and a congratulations message.
Read up on the URI-routing of symfony. localhost/web/frontend_dev.php/module/action/param/value, that's the basic default routing.
So it will call the action in your module and pass the parameter's value.
Do anything you want with it.
That said, you will have to read up on how symfony works. The framework can help you with a lot of things, if you know how it works. If you don't it will be more likely slowing you down.
Start here: http://www.symfony-project.org/get/pdf/jobeet-1.4-doctrine-en.pdf it will walk you through from beginning to end of a rather extensive project. Some of the things might seem a bit clumsy, but that is because in the process they WILL show you most everything that framework can do.

Related

2SXC/DNN - Delete ADAM Files in Entity

We're designing a system for a client where they are allowing authenticated users to upload images. We've created an API to upload the files but the client only wants the latest file and delete all previous ones so that there would only ever be one.
We've looked through the docs and can't come across a way for ADAM to handle this in both 2SXC and DNN's file system.
Internally when deleting images we see API calls like the following to the internal 2SXC API, but we're wondering if this is exposed somewhere within the public API?
https://somedomain.com/api/2sxc/app/auto/data/61393528-b401-411f-a001-f423ea46700a/b7d04e2c-c565-496c-8efb-aa133cf90d33/Photo/delete?subfolder=&isFolder=false&id=189&usePortalRoot=false&appId=3
We could probably use the same endpoint above, but we'd likely run into permission issues or changes to the APIs that could be problematic.
Thank you for any advice you can give! Perhaps #iJungleBoy can provide some thoughts on this.
As a solution from a completely different direction, if you are on the later release of 2sxc (v12.8+, v13+), and comfortable programming in C#, you might consider doing this as a "cleanup" from a Dnn Scheduled Task. This can be done with a relatively easy setup. We have a Gist in place that we use as a starter. You simply put the code in the /App_Code folder then setup a normal Dnn Scheduled Task. NOTE that you can scroll down to the first comment on the Gist to see a screenshot of a complete working setup.
Accuraty's AccuTasks template on GitHub Gists
There are two more key things to note:
You need to install Dnn's CodeDom 3.6 because the example uses the later versions C#'s string interpolation - OR remove the few $"ASL2021 - {this.GetType().Name}, Task Scheduled Email", bits or convert to string.Format() or something.
Since your task's code is NOT running in a (2sxc) module, if needed, you'll do stuff like this: 2sxc Docs - Use 2sxc Instance or App Data from External C# Code
So, if you are comfortable writing code that "finds and deletes stuff older than NN days" - this might be the way to go.

Is there an automated way to document Nancy services?

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.

Yeoman sub generators for MEAN application?

I've been playing with Mean.IO (http://mean.io/), and wondered if there was a Yeoman generator (sub-generator?) that I could use to auto-generate code for an "entity" across the entire stack. For example, in the mean.io project there is an "Article" example that contains 7 components related to "Articles" (Model, Controller, Node Routes, Angular Routes/Service/Controller/Views). Is there a generator that will create this "component stack" for a custom entity?
eg, something like:
yo meangenerator:entity 'MyEntity'
would then create 7 different files that tie 'MyEntity' into an existing MEAN application.
Couldn't really find anything that worked how i wanted, so I wrote my own. My first Yeoman generator, as well as first real interaction with github and https://npmjs.org/. Fun!
GitHub:
https://github.com/MartyIce/generator-meancrud
NPM:
https://npmjs.org/package/generator-meancrud
Actually i think they have something similar, like:
$ mean package ThingIWantToModel
Don't know if they created this feature after you asked.
I wonder if we can generate singular controllers, models, and anything else inside this package.
Mean.js (another project that is similar to mean.io) has a great module generator, as does the angular-generator-fullstack project.
I think mean.js is the best, though, as it comes out-of-box with everything you need to actually get started building your application, including user logins, registration, reset password, change password, and a user management interface. Basically, batteries are included and you are ready to get building!

create.js, createPHP and Cakephp

We are trying to implement in page editing for our cake app. We would like to use create.js for the frontend and createphp to handle the connection between create.js and cakephp. I have been doing a lot of research on RDFa and I am generally baffled by how all this links together.
What I have:
Editable interface
Endpoints via actions in cakephp
What I need:
A way to convert the data sent by create.js to my database structure and a way to send data to create.js for rendering.
I have gotten to the point in createphp where you are supposed to create your own mapper. I don't know what the mapper should contain. It mentions that is has built-in mappers (Midgard\CreatePHP\Mapper ?) but I don't know how to load those either.
I have read the documentation but it doesn't give details on how to accomplish these tasks.
Thank you for your help on the two following questions.
1. How can I convert my data from create.js to cake and then back again for the views? (possible solution createPHP but doesn't have to be)
2. How do I create a mapper for createPHP or where could I find information to learn how to create a mapper for my instance?
Yeah, the documentation is unfortunately rather sparse. I will create an issue on createphp linking to this post, to give some hints how the documentation could be improved.
I try to explain how things work:
To convert the data from the REST call to your model, you indeed need a RdfMapper instance. See the setup section of the tutorial how you bootstrap that. the bundle comes with mappers for doctrine, which you can read for inspiration if you do not use doctrine. I recommend to extend AbstractRdfMapper in that case.
To render the rdfa, you need to configure what fields of your class should be what rdf type. You can either use the array mapper as in the tutorial, or use the xml mapping, or your own RdfDriver
The whole process is working fine in the symfony2 CreateBundle.

Cakephp scaffold, leave it or remove it?

What's the best way to handle the scaffold when it comes to the deployment stage?
Leave it there? But then what's the best way to protect the access of it?
Remove it? But then I need another system to access all the data, right?
How do people usually handle the scaffold in CakePHP which is very useful in the building process?
Most people would not use scaffold anymore when getting close to deployment.
That is where "bake" comes into play.
You usually only scaffold while still changing the database structure heavily.
As soon as it gets stable you use custom bake templates to bake your views to real files.
I actually never use scaffolding as bake has way more advantages (such as full customization of the template output.
And rebaking is not that big of a deal. It is pretty fast to achieve.

Resources