HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
how to write the validation using API format
riyan
New
give me some tips creating validation using controller and model where i write the code of that
0
Comments
Please don't get me wrong: I really do not want to be impolite, but what is the question?
"Validation API format" doesn't exist.
"Where" to write code depends on what piece of software you are creating. Tell us what you have and what you want to achieve and we might be able to support
"Example for validating, controller, model" - Vanilla has a great inline documentation, so if you look at any of the included models, you should be able to find examples. If you cannot understand them, show the code and ask a specific question
In order to help you, you need to help us to better understand what exactly you are asking for. I'm always happy to provide code snippets.
Thank you for replying..
Sorry it's my mistake how to write the error validation on API using validation PHP
If you want assistance here, you’ll need to provide more information. I. An only guess the kind of vague area you’re asking about but maybe this will help you?
Looking at existing classes is quite useful as well. You can try and look at any ApiController in the app to see what’s going on.
thank you.....
Please take a look at e.g. the DiscussionsApiController and /vendor/vanilla/garden-schema/src/Schema.php
Simply by looking at that I could see that validation uses the Schema class and the DiscussionsApiController has quite a lot of examples. This is what I came up with:
@R_J I'll note best practice for these controllers (as documented) is to always have a `$this->permission()` call even if it's an empty string. This allows "default" permissions to be enforced (if the site is configured to have escalated default permissions).
I do not really have read the documentation, I just wanted to quickly assemble some working code. Thanks for giving that extra information. But now that you have mentioned it, I have taken a look at the Schema docs and I have found that:
In this example the type shortcut and the name are the other way around. That looks like an error...
I also cannot see what
'score:i|n' => 'Total points associated with this post.',
would mean (taken from the DiscussionsApiController). What does this "|n" stands for?Hmmm. That documentation is definitely incorrect. The scheme is its own package though and has better documentation it’s github repo.