How can I use Codeigniter 3 validation library in other framework - validation

I want to develop API in ZF2 framework and I want to use CodeIgniter 3 validation library for validate API request parameters. So is it possible or not. If possible so how can I do it. Suggest any solutions please.

Short answer is no. You can't use it in Zend or any other framework.
Form validation library of the Codeigniter is actually not a library, its just a god object which is tightly coupled to the framework's itself. It also contains multiple bad practices such as using global function calls, not respecting PSR standards and breaking multiple object oriented design principles.
I strongly recommend to use zend-inputfilter component. You can easily validate and sanitize any kind of incoming data using it.

Related

Ajax validation for Go programs

Is there a Go package that supports data validation for restful apis?
It would be good if there were something similar to active model validation in Ruby?
I tried various ways but couldn't find something that offers good abstration of this need.
go-validator has support for tags and custom validators on top of the built-in ones. It can easily be added to the models for your API resources.

MVC with node.js: expressjs, backbonejs, railwayjs

I'm going to build an app using a lot of interfaces for the user to insert data which should be stored in a database. I developed applications in PHP before using Symfony2. Now I want to use node.js but I'm not sure what to use expressjs, backbonejs, railwayjs.
For the application I need a MVC structure, form validation and a good database ORM. Which of these 3 should I use? What's the main different between these?
If you coming from rich framework like Rails or Symfony your choise is RailwayJS, but if you like something minimal and not well-structured, use ExpressJS.
What's the main different between these
RailwayJS is extended ExpressJS with routing, controllers, localization, generators, rich logging, ORM and other stuff built in, right over expressjs. But in general you can use it in the same way as express: middlewares, express routes, tests, etc. So you can use any middleware written for express/connect, you should just put it in proper place (config/environment.js for common env, or config/environments/{development|production}.js for env-specific.
Express is becoming more or less the de facto choice for web development framework. You can totally do MVC development with it, the view being your templating engine (jade, for example), the model being provided by your ORM (mongoose is an excellent choice should you go with MongoDB), and your route handlers/app logic/middleware being the controller.
Backbone provides MV* structure for your client-side development, so it is complementary to (and independent of) whatever server-side framework or library you choose. There are many options for client-side MVC or MVVM code organization, such as knockout.js and ember.js, but personnally I prefer Backbone, which has less magic but offers more control. This is relatively subjective, though, so this is not really a relevant debate for stack overflow.

MVC2 validation - pure jQuery based validation or use Microsoft scripts?

We've an ASP.Net MVC2 web app (SQL 2008 in backend). We use Data Annotations at model level for all sprt of validations (hope its one of the best practices). So, our validations are performed on server side and errors (if any) are returned. Works fine.
Next, we've AJAX based postback jQuery plugin. In combination with MVC partial views, we've 'AJAXified' certain forms. I hope this is pretty much like a basic stuff with a little AJAX & jQuery.
Now, we want to bring the validation on client side as well (and still
persist the server side validation). We've found some simple &
basic way to have basic validations like required, format,
range, etc... using bassistance jQuery. But what about certain server
side validations, like duplication check, etc.. what are the best
practices?
Note that we've simplified our web app by not including the default Microsoft AJAX libraries. We prefer simplified jQuery plugins. Also Microsoft js files weight several KB. Though it might lesson the effort but it requires several files.(Data Annotations Validation + jQuery.Ajax Post)
For example, jquery forms plugin looks simpler then the default MicrosoftAjax.
jQuery plugins are abstract & self contained thats one reason we're away from the Microsoft scripts. Here're some options -
SOLUTION #1:
Using ASP.Net Data Annotations validations using pure jQuery, AJAX,
JSON & Partial views
SOLUTION #2:
ASP.NET MVC Client-Side Validation Summary with jQuery Validation Plugin
We need to keep things simple, clean and optimal. For example, this looks complex -
ASP.Net MVC: Can you use Data Annotations / Validation with an AJAX / jQuery call?
If possible we'd prefer to keep the validation in one place instead of having to replicate it in data annotations as well as in jQuery.
Thank you.
But what about certain server side validations, like duplication
check, etc.. what are the best practices?
In ASP.NET MVC 3 you could use the [Remote] data annotation.
In ASP.NET MVC 2 it doesn't exist but you could implement it using jQuery.validate remote rule. This assumes that you use the jQuery validate plugin of course instead of the built-in Microsoft client side validation framework.
Microsoft scripts are now obsolete. If you want to ease the migration towards ASP.NET MVC 3 and even 4 you should forget about those and use jQuery and jQuery validate which are the default client side frameworks now in ASP.NET MVC.

Looking for way to reduce duplication of validation code in my View Models and Logical Layer

Right now the application being built by our team uses the built in MVC attributes and a few home baked ones to validate the View Models. Because of best practice design principles, we have placed those same rules in the Logical Layer. This has unfortunately caused duplication of validation code.
In MVC3 at least, if JavaScript is disabled, these same attributes will still perform the validation they are meant to, so transforming a View Model in to a DTO and asking the Logical Layer to validate it is not an option because this process would have already been done by the framework.
I have not found the following SO post to be of any help. I have used MS Enterprise Library and the API did not sit well with our team.
Good practices for avoiding validation logic duplication when working with both domain objects and view models in ASP.NET MVC
I'm thinking that the best way to do this is to have the validation attributes bound at runtime to specific properties and have a dependency injection container do this. Is this possible or is there a different approach we could take?
You are asking for multiple validation types to be performed here.
You want client validation (it seems) and some other business validation layer.
If thats the case the only choices as I see it are:
duplicate the code (ya I know Im listing options)
1a. use data annotations on your objects for client validation. Business layer validation happens however you define, and separate as a final check. If you use for instance the entity framework's fluent API this is a standard route.
client side validation is just that - helpers for client side. domain validation will happen upon save. This is ideally the more powerful approach, but isn't as friendly when your domain objects don't match property names on your view models, so you need to map domain errors to view model property errors which normally isnt too bad but can get iffy.
implement IValidteableObject (and rid of client validation). This validation logic is then called from your logical layer and the model binder.
You can inject code for validation, but its not pretty and Im not sure how reusable it is outside the MVC validation route.
There may be other ways beyond this, but those are the main options as I see it.
One way of seeing it is: If your api is your mvc application and the validation is already done by the point you are executing your business rules, you can just assume they are valid. It's input validation, of course is something related to your domain but... if you change the way of thinking, your domain expects valid data and assumes you did your homework before using the business rules.

What is the current best validation framework for asp.net apps?

To make sure its a DRY approach all validation logic should of course go in the business logic (model).
How are validation messages presented to views, should be able to localize error messages
Can you generate javascript from the validation framework. Compatibility with JQuery would be perfect
Is the framework compatible with a DbC approach?
Edit:
I think this is the nicest one until now, Castle validator + live validation
http://blog.codeville.net/2008/04/30/model-based-client-side-validation-for-aspnet-mvc/
Validation Application Block
from Microsoft is one alternative but I have no experience with it

Resources