ballhogjoni Posted June 3, 2012 Share Posted June 3, 2012 So i am writing my own mvc framework just for my own knowledge. I can't figure out how to render the view automatically. Does anyone have any suggestions or ideas? Quote Link to comment https://forums.phpfreaks.com/topic/263603-mvc-auto-render-view-question/ Share on other sites More sharing options...
requinix Posted June 3, 2012 Share Posted June 3, 2012 If it's your own framework then you do it however you want... You have some code that calls the controller/action, right? Shortly after that it can render the view. Quote Link to comment https://forums.phpfreaks.com/topic/263603-mvc-auto-render-view-question/#findComment-1350954 Share on other sites More sharing options...
ballhogjoni Posted June 3, 2012 Author Share Posted June 3, 2012 I am using this example http://www.markisgood.com/blog/php/create-your-own-lightweight-php-mvc-framework I don't want to have to run this code $this->registry->template->show('methodView.php'); at the end of every action. Quote Link to comment https://forums.phpfreaks.com/topic/263603-mvc-auto-render-view-question/#findComment-1350957 Share on other sites More sharing options...
requinix Posted June 3, 2012 Share Posted June 3, 2012 So change it to something you prefer. Like rather than call show() you can set a view name using a default of "(action)View.php". The Router then calls a method on BaseController to show the view, and that method basically does $this->registry->template->show($this->viewName); I would structure it like // router controller = new controller; controller->execute(action); // BaseController::execute this->viewName = action + "View.php"; this->action(); this->registry->template->show(this->viewName); // controller::action this->viewName = "customView.php"; Quote Link to comment https://forums.phpfreaks.com/topic/263603-mvc-auto-render-view-question/#findComment-1350959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.