Liquid Fire Posted October 13, 2008 Share Posted October 13, 2008 Here is a list of what I am making sure is 100% solid in my framework before I release to the public for test and what I consider to be need to be called a MVC Framework: load a single view <?php //load the index.php view for the site controller NOTE: location is by default the name of the controller and not needed most of the time $this->load_views(array('index.php' => array('data' => $data, 'location' => 'site'); ?> load multiple views <?php //load the index.php view for the site controller NOTE: location is by default the name of the controller and not needed most of the time $this->load_views('side.php' => array('data' => $side_data, 'location' => 'site', array('index.php' => array('data' => $data, 'location' => 'site'); ?> store data on a view by view basis <?php //$side_data is only visible to side.php and $data is only visible to index.php $this->load_views('side.php' => array('data' => $side_data, 'location' => 'site', array('index.php' => array('data' => $data, 'location' => 'site'); ?> be able to add css to header data <?php $this->add_css('/api/css/site.css'); ?> be able to add javascript to header and/or footer data <?php //NOTE the second parameter is 'footer by default as javascript should be at the lowest point in the html for best practices $this->add_javascript('/api/javascript/framework', 'header'); $this->add_javascript('/api/javascript/site.js') ?> create a database connect <?php $database = database::get_instance(); ?> parse url for domain, controller, controller method, and parameters <?php $this->url_helper->get_domain(); $this->url_helper->get_controller(); $this->url_helper->get_method(); $this->url_helper->get_parameters(); ?> create empty model <?php $user = new user_model(); ?> load model by passing primary key value in constructor <?php $user = new user_model(1); ?> set/get functions for all data <?php $user = new user_model(1); echo $user->get_username(); $user->set_username('superadmin'); ?> simple saving process <?php $user = new user_model(1); //update data... //this function automatically knows if it is a insert or update save $user->save(); ?> load model by a field or field combinations with a model object <?php $user = new user_model(); $load_criteria = array ( 'username' => 'admin', 'password' => 'password' ); $user->load_by_fields($load_criteria); ?> be able to perform a search query on a models database structure with an internal format <?php //I am open to suggestions on the format as this is just something that I came up with myself $search criteria = array ( 'created_date' => array ( 'condition' => '>', 'value' => '2007-01-01' ), 'status' => '1' ); //this will return all user that were entered after 2007-01-01 and have a status of 1 $users = user_model::get($search_criteria); ?> This is right now the core list of functionality that I think all MVC frameworks should have to be called a “MVC” framework. Stuff like scaffolding and whatever I feel are extras but no required. What other things would you put on this list? Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/ Share on other sites More sharing options...
Liquid Fire Posted October 13, 2008 Author Share Posted October 13, 2008 Another things is auto code generation for model files. Not that it is really a requirement to be called a MVC framework to me but after the early version on my framework not having it, I would never a MVC framework without it. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-664368 Share on other sites More sharing options...
Daniel0 Posted October 14, 2008 Share Posted October 14, 2008 To be called an MVC framework then you need to be a framework that uses the MVC design pattern... Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-664787 Share on other sites More sharing options...
Liquid Fire Posted October 14, 2008 Author Share Posted October 14, 2008 To be called an MVC framework then you need to be a framework that uses the MVC design pattern... I guess that is technically a good answer to my question so let me rephrase it, the new question would be: "What functionally do you want to see to be considered a full fledged MVC framework and what functionality do you want out of the box" For instance, IMO, codeigniter is not a full fledged MVC framework because it does not really have much in the terms of the Model portion. The model class seem to only provide controller syntax to the model and that is it. For me, the "Model" functionality of a MVC framework should at a minimum allow you to load data, provide set/get methods for all data, provide 1 method save function that insert and update automatically based on the model's status, able to preform a search or any number on the model data members. Codeigniter does none of that is the base code and while you can do as the forum suggested to me, incorporate an existing ORM like Propel of Doctrine, I feel the MVC Framework should already have that functionality in there(even if it is just including an existing ORM like symfony does). Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-665013 Share on other sites More sharing options...
keeB Posted October 16, 2008 Share Posted October 16, 2008 I should never have to instantiate a Model. Your view should do it for me and just provide me what I need in my Templates. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-666852 Share on other sites More sharing options...
Liquid Fire Posted October 17, 2008 Author Share Posted October 17, 2008 I should never have to instantiate a Model. Your view should do it for me and just provide me what I need in my Templates. Could you elaborate on what you mean(with possible code example)? What do you mean instantiate but to me that means creating a model and if i want to get a user model with the id of 10 that only easy way to do that is: $user = user_model(10); which should be in the controller. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-667942 Share on other sites More sharing options...
Acs Posted October 17, 2008 Share Posted October 17, 2008 In my framework I do: $this->loadmodel("teste"); To load the teste model and then I access/change this way: //create new stuff $this->teste->texto = "uuuuuu"; $this->teste->contador = 111; $this->teste->save(); $this->loadmodel("counter"); $this->counter->fetch_counter(); echo "Values -> " , $this->counter->counter++ , "<br>"; echo "Values -> " , $this->counter->counter; $this->counter->save(); One thing I would like to know is how are you implementing those add_javascript and add_css functions? Are you just replacing the head with <head><style> etc... and doing the same for the </body> tag with the javascript function? Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-667946 Share on other sites More sharing options...
Liquid Fire Posted October 17, 2008 Author Share Posted October 17, 2008 In my framework I do: $this->loadmodel("teste"); To load the teste model and then I access/change this way: //create new stuff $this->teste->texto = "uuuuuu"; $this->teste->contador = 111; $this->teste->save(); $this->loadmodel("counter"); $this->counter->fetch_counter(); echo "Values -> " , $this->counter->counter++ , "<br>"; echo "Values -> " , $this->counter->counter; $this->counter->save(); Now i am assuming that in those above cases the class name of the models are teste/counter, is that correct? A question i would have is how would i load 5 users in a controller? One thing I would like to know is how are you implementing those add_javascript and add_css functions? Are you just replacing the head with <head><style> etc... and doing the same for the </body> tag with the javascript function? Basically in the configuration of my framework you can set whether or not to automatically include a header and footer view file, and you if you do you configuration the name of the header and footer and the module they are located in. Now all add_javascript/add_css does is add an array of those file names to the header data and footer data, which is in the base page controller that all controller must extend, and then it is up to you to inside your header and footer loop through that array and include the files. Also the way the auto include of the header and footer is done when you use the load_page function from the base page controller which you pass a multi-dimension array of all the views to load in order and then in the background the load_page loads the configured header first passing the header data to it, then all the views you passed to it, and then the footer with the footer data. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668005 Share on other sites More sharing options...
Acs Posted October 17, 2008 Share Posted October 17, 2008 I don't understand your question. What do you mean by 5 users in the controller? Did you mean models? Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668044 Share on other sites More sharing options...
Liquid Fire Posted October 17, 2008 Author Share Posted October 17, 2008 I don't understand your question. What do you mean by 5 users in the controller? Did you mean models? sorry, yea, i meant 5 of the same type of model. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668063 Share on other sites More sharing options...
Acs Posted October 17, 2008 Share Posted October 17, 2008 Why would you want to load 5 models of the same type? Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668064 Share on other sites More sharing options...
Daniel0 Posted October 17, 2008 Share Posted October 17, 2008 Why would you want to load 5 models of the same type? If he has five items he has to load? Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668079 Share on other sites More sharing options...
Acs Posted October 17, 2008 Share Posted October 17, 2008 But my idea of model is not one model for every row. And if you have more stuff to update, delete etc you just do one thing then save then do the other than save. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668083 Share on other sites More sharing options...
Daniel0 Posted October 17, 2008 Share Posted October 17, 2008 Traditionally a model represents an object. E.g. an instance of Person could be me and an instance of Book could be one of my books. If I have more books then I have more Book objects. You can save resources by using lazy loading and thus only initializing the objects in the book collection when needed yet still fetch all of them from the database. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668151 Share on other sites More sharing options...
Acs Posted October 17, 2008 Share Posted October 17, 2008 Ok ok I think I get what you're saying. Mine don't work like that, but maybe they will Thanks Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668248 Share on other sites More sharing options...
quantumgroup Posted October 18, 2008 Share Posted October 18, 2008 To be called an MVC framework then you need to be a framework that uses the MVC design pattern... Yeah, that's pretty much it. Even to be a full-fledged framework. I mean, that definition between "framework" and the "MVC design pattern" covers it. Quote Link to comment https://forums.phpfreaks.com/topic/128231-what-does-it-take-to-be-called-a-mvc-framework/#findComment-668797 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.