Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Industrial Strength MVC
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Article Discussions
View previous topic :: View next topic  
Author Message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Sep 06, 2003 4:43 am    Post subject: Reply with quote

Consider cached pages. For simplicity, imagine a query string based access method for pages. Using the 404 error handler as Monte suggests, have the 404 controller implement a publish method which acts just like display() except that the cached image is also copied into the webroot with the saved page's name including the query string parameters. This way, the first time a page is called, it invokes the controller, but subsequent calls are served completely statically. The problem is invalidating the cache in the case that a new document needs to be generated. Are there any good ideas to address that short of running a cron job of some sort?
Back to top
View user's profile Send private message
mshaffer
Smarty Rookie


Joined: 18 Dec 2003
Posts: 12

PostPosted: Sat Dec 20, 2003 6:44 pm    Post subject: Re: Industrial Strength MVC Reply with quote

sweatje wrote:
Industrial Strength MVC is the sample article for the June issue of PHP|Architect.

....

I hope you find it useful.


This article was very useful. I even dowloaded the first article in the series. I really like the idea of creating and developing usings standards. PHP allows the designers to do stuff, but when real quality work needs to get done, a framework needs to be created. I like the standards of MVC mostly because they were created from some great ideas originally (PARC), and because non PHP, JAVA programmers can pick up the syntax more readily.

I do have a question regarding abstraction. In the Article "Industrial Strength" you choose to use PostGreSQL, which is my database of choice for the last 2 years for many of the reasons you mention in this article.

The issue I have is with the database abstraction. I believe abstraction is important, but I feel that if I choose to used the PEAR:Very HappyB or ADOdb in my PHP code, then I can't create the pgsql functions. All of the logic would have to reside in the scripting logic to allow for the database abstraction to work.

So if I were to port the application to another database, the data integrity component would not work.

I am trying to come to some personal conclusions on building a framework, and am learning that for "Industrial Strength" applications, you have to pick your race horse, and I choose PostGreSQL.

Any insights into this issue of abstraction would be greatly appreciated.
Back to top
View user's profile Send private message
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Sun Dec 21, 2003 3:08 am    Post subject: Re: Industrial Strength MVC Reply with quote

mshaffer wrote:
The issue I have is with the database abstraction. I believe abstraction is important, but I feel that if I choose to used the PEAR::DB or ADOdb in my PHP code, then I can't create the pgsql functions. All of the logic would have to reside in the scripting logic to allow for the database abstraction to work.

So if I were to port the application to another database, the data integrity component would not work.


I feel the main benefit I get from using a database abstraction library like ADOdb is to get common calling conventions between databases (particularly when I switch from Oracle as work to MySQL, Postgres or Sybase at home).

If I were to implement a project where I wanted to support multiple database, then the db abstraction would be a small piece of the overall design. I would create the database access using Table Data Gateways (in J2EE DAOs), and therefore have simple class methods for accessing the data without specifying any SQL. On top of theses, I would implement a Strategy pattern to choose the appropriate DAO based on what this particular instance of the application was configured for. In this way you could have DAOs for Postgres, Oracle or Sybase coded with functions, or a MySQL DAO with several additional SQL calls for handling things like referential integrity hidden within the public methods of the DAO.

I just release a data caching project that implements some of what I am talking about at http://phpdatacache.sourceforge.net/ if that helps.

Regards,

Jason
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
proop
Smarty n00b


Joined: 07 May 2004
Posts: 4

PostPosted: Fri May 07, 2004 11:45 am    Post subject: Validate Reply with quote

Hi Jason,

Maybe you got this twice, I accidently posted this in the wrong forum (Embarassed)

The question is as follows: I have a custom ActionForm object en I use the "validate" method. But when I submit some values, and "validate" returns FALSE, the intended view is displayed but my submitted values are gone! Sad

How can I tackle this problem so that my previously submitted values are displayed for correction?

Thnx!
_________________
Backups are for weenies
Back to top
View user's profile Send private message
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Fri May 07, 2004 11:57 am    Post subject: Re: Validate Reply with quote

proop wrote:
The question is as follows: I have a custom ActionForm object en I use the "validate" method. But when I submit some values, and "validate" returns FALSE, the intended view is displayed but my submitted values are gone! Sad

How can I tackle this problem so that my previously submitted values are displayed for correction?


I tend to use part of some model class to store the previous data in the $_SESSION.

Something like:
[php:1:cf1ef6bc67]define('FORMWIZ_SESSION_KEY','__form_wizard__');
class FormWizard {
var $state;
function FormWizard() {
if (!array_key_exists(FORMWIZ_SESSION_KEY,$_SESSION)
&& is_array($_SESSION[FORMWIZ_SESSION_KEY])) {
$_SESSION[FORMWIZ_SESSION_KEY] = array();
}
$this->state =& $_SESSION[FORMWIZ_SESSION_KEY];
}

function SaveVars() {
$this->state['formvars'] = $_POST;
}
function RememberVars() {
return $this->state['formvars'];
}
}[/php:1:cf1ef6bc67]
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
proop
Smarty n00b


Joined: 07 May 2004
Posts: 4

PostPosted: Fri May 07, 2004 12:36 pm    Post subject: Re: Validate Reply with quote

sweatje wrote:

I tend to use part of some model class to store the previous data in the $_SESSION.


So if I get this right, the view must look if there is a previous post en there are some errors and then get the vars for assigning to smarty from the session? And if there are no errors get the data from the database?
_________________
Backups are for weenies
Back to top
View user's profile Send private message
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Fri May 07, 2004 1:33 pm    Post subject: Reply with quote

Well, this is how I might think about the whole interaction from a MVC view point.

>>>start of transaction 1
To start, the browser sends and HTTP request.

This is picked up by the Controller, who determines the action that needs to take place is to show a view that contains a form.

<<<end of the first transaction

>>>start of transaction 2
The user submits the form using POST

The controller determins the action that needs to take place is form validation.

The action (still part of the controller) knows which post vars are relavent for validation.

The action creates a model, and uses validation methods of the models to determine if the information is correct according to your business rules (i.e. the model has no idea about $_POST, only the controller does)

The model method for validation returns false indicating a problem.



You now have two choices:
a) call the action with shows the view, but let it know the current $_POST values (this has the disadvantage of giving the user the "repost" message if they hit refresh
or b) store the vars in the session, and use a header('Location: ...'); redirect to a ShowView action (which is my preference, and the start of which I sketched in the above post).

Does that make any more sense?
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
proop
Smarty n00b


Joined: 07 May 2004
Posts: 4

PostPosted: Mon May 10, 2004 11:31 am    Post subject: Reply with quote

sweatje wrote:
Well, this is how I might think about the whole interaction from a MVC view point.

>>>start of transaction 1
To start, the browser sends and HTTP request.

This is picked up by the Controller, who determines the action that needs to take place is to show a view that contains a form.

<<<end of the first transaction

>>>start of transaction 2
The user submits the form using POST

The controller determins the action that needs to take place is form validation.

The action (still part of the controller) knows which post vars are relavent for validation.

The action creates a model, and uses validation methods of the models to determine if the information is correct according to your business rules (i.e. the model has no idea about $_POST, only the controller does)

The model method for validation returns false indicating a problem.



You now have two choices:
a) call the action with shows the view, but let it know the current $_POST values (this has the disadvantage of giving the user the "repost" message if they hit refresh
or b) store the vars in the session, and use a header('Location: ...'); redirect to a ShowView action (which is my preference, and the start of which I sketched in the above post).

Does that make any more sense?

Not yet! I still can't see no other option than that the view (and indirectly the template) makes the descision of wheter to pull the values from the database model or from the "FormWizard" class.
Do you have an example from the view file, and the action file?
_________________
Backups are for weenies
Back to top
View user's profile Send private message
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Mon May 10, 2004 11:47 am    Post subject: Reply with quote

Perhaps the issue is in how I think about the loading of the template vars. I typically have "View" classes that:
a) are created via a factory method of a "ShowViewAction" class
b) have a Smarty object, created in the ShowViewAction and loaded with common variable assigned to is
c) each "View" class assignes further view specifc variable to the Smarty object, along with choosing the template to use.

Now "View" may be the worst choice of a name for these classes because they really are still engaged in the actions of the Controller, i.e. deciding what models to use and what data to assign to the template. The Smarty template then is the proper "View" from the MVC framework.

HTH
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
proop
Smarty n00b


Joined: 07 May 2004
Posts: 4

PostPosted: Tue May 11, 2004 2:46 pm    Post subject: Reply with quote

sweatje wrote:
Perhaps the issue is in how I think about


Ahah, I get the hang of this now!
If there are some more people with questions about the subject, perhaps you could write an article about it?

Thanx !!
_________________
Backups are for weenies
Back to top
View user's profile Send private message
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Tue May 11, 2004 4:49 pm    Post subject: Reply with quote

Sorry for the cross post to another forum, but this thread in an interesting examination of MVC with an underlying question of is MVC becoming an "anti-pattern"?
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
gerard
Smarty Regular


Joined: 18 Apr 2003
Posts: 84

PostPosted: Tue Nov 30, 2004 1:25 am    Post subject: Reply with quote

I just saw this thread. Have Monte's controller ideas been further fleshed out at all? I've had similar thoughts.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Article Discussions All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP