Jump to content

Recommended Posts

 

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?

 

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.

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).

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.

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?

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.

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.

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.