VelvetMirror Posted April 14, 2011 Share Posted April 14, 2011 So I've been reading and reading MVC examples for the last few days and I still can't get a grip on how to do it right (without using frameworks).This is the best tutorial I found so far: http://www.phpro.org/tutorials/Model-View-...roller-MVC.html (it also includes a zip with the code)But I'm unnable to try the blog section that includes, if I type localhost/mvc it shows the expected index, but if I type localhost/blog or localhost/index.php?rt=blog it doesn't find the page. So if I can't success in running the sample section (blog), how can I write my own and expect to make it work?Hopefully someone can give it a try and tell me what's wrong, I would truly appreciate it.Also if someone has a recommendation of a good tutorial or book for MVC in PHP, I'm all ears. Link to comment Share on other sites More sharing options...
Fmdpa Posted April 15, 2011 Share Posted April 15, 2011 By far the best tutorial I've seen is this one. Link to comment Share on other sites More sharing options...
VelvetMirror Posted April 15, 2011 Author Share Posted April 15, 2011 Thanks for the link, it is very instructive indeed. Although it doesn't seem to me very clear how to escalate the proyect and add more pages or sections using that structure. Link to comment Share on other sites More sharing options...
Fmdpa Posted April 15, 2011 Share Posted April 15, 2011 Just add more methods in the controller class and remember to create views associated with each method. Link to comment Share on other sites More sharing options...
VelvetMirror Posted May 9, 2011 Author Share Posted May 9, 2011 Just add more methods in the controller class and remember to create views associated with each method.The problem is that when you create a new controller in the tinyMvc.php file:<?phprequire 'load.php';require 'model.php';require 'controller.php';new Controller(); The __construct() method is called in the controller.php file: class Controller { public $load; public $model; function __construct() { $this->load = new Load(); $this->model = new Model(); // Set what page you're on $this->home(); } function home() { $data = $this->model->get_index(); $this->load->view('index.php', $data); }} In which you have to set the webpage you're on in order to load the view.So if you create another page which also loads TinyMvc.php, it would still load the index.php view. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.