scope of objects stored in the registry-class php -
I have a registry where I store my request, verifier, database and router objects. Therefore, for the recognition of my forms, I use a method in class MyForm where the input field is checked. When user input is incorrect, then Registry :: getInstance () -> validator-> setErrors ($ errors) is called so that the errors are stored in the registry and available anywhere in the code.
This is the reason why I call Registry :: getInstance () -> validator-> getErrors () in MyView.php
isValid () gets here in the registry: getInstance () -> validator-> setErrors ($ errors) to look clearly with var_dump (Registry :: getInstance ()), validator object The tap is when it's called in MyView.php. So it is still the same thing but why mistakes have gone?
And where recognition in MyForm.php is false, can I capture text in MyView.php?
EDIT: This is Registry
class registry {Private static $ _instance = null; Private $ _cache = array (); Public stable work getInstance () {if (null === self :: $ _exam} {self :: $ _ instance = new self;} return self: $ _ example;} public function __set ($ index, $ value ) {If (empty! ($ Index) & amp; is_string ($ index) & amp;! Array_key_exists ($ index- $ this-> _cache)) {$ this -> _cache [$ index] = $ Value;} Else {// error here ...}} public function __get ($ name) {if (array_key_exists ($ name, $ this-> _cache) & amp; amp; amp; amp ; Amp; amp; blank ($ this-> _cache [$ name]) {$ $ this-> _cache [$ name];} and {return tap;}} public function __unset ($ index) { without Set ($ this-> _cache [$ index]);} personal function __construct () {} private function __clone () {}
}
Looks like this and have to do it with the communication between the controller. It does not work in any way. I do not know where to add the view, which is just html, is not generated. It is my registration controller.
class registration controller controls {public function execution () {$ form = new RegistrationForm; If ($ this-> request-> issetPost ()) {$ posts = $ this- & gt; Request-> GetPosts (); If ($ form-> isValid ($ posts)) {// [..ave.]}}}
} I'm still confused with the scene:
Switch ($ page) {case 'index': // break; Case 'news': // break; Case 'register_new_user': $ newuser = new registration controller; $ Newuser- & gt; Icon (); break;
} Where is the place to say a scene, tell that the action was with errors, so there is a text in the registry-container to show?
While your variables remain intact in a single request, subsequent requests are still an old registry The set solution of the variable will be to store the
Registry
singleton (in one session) in a session, and the first must load those variables immediately. Something like this:
.... if (tap === self: $ _ example) {if (! ($! Session) (session ($ _ session)) session_start ( $ '_ Instance = isset ($ _ session [' Registry '])? $ _SESSION [' Registry ']: New Auto ($); $ _SESSION [' Registry '] = self: $ _ Example;} .... (
or just a part:
.... if (tap === self: $ _ example) {if ( ! Isset ($ _ session)) session_start (); auto :: $ _ example = new self (); if (isset ($ _ session ['registry copy']) auto: $ _ example-> _cache ['persistent '] = & Amp; $ _ session [' registry persistent '];} ....