I find examples and tutorials about models and about validation. And I places that say the validation (or most of it at least) should be in the model, which I agree with. But I can’t any examples or tutorials that show how that should be done.
Could anyone help me with a simple example on how that could be done? Where would you have the rules in the model? Where would the validation happen? How would the controller know if the validation passed or fail? How would the controller get error messages and things like that?
Hope someone can help, cause feel a bit lost here :p
I too had difficulty finding examples for Kohana3, bestattendance’s example is for Kohana2.
Here’s an example I threw together in my own testing:
application / classes / model / news.php
application / messages / errors.php
application / classes / controller / news.php
application / views / news.php
To get this code working in a default install, you would have to enable the database module and configure it for authentication. Then you can access it from index.php/news using default configuration.
It is tested in Kohana 3.0.7 and should give you a good starting point of how you might lay out code. Unlike other frameworks, Kohana seems to be very open ended as to where you put your logic so this is just what made sense to me. If you want to use the ORM instead of rolling your own database interaction, it has its own syntax for validation which you can find here