|
View:
New views
16 Messages
—
Rating Filter:
Alert me
|
|
|
MVC - where can I learn more about the "model"?Hi,
I'm a total newbie, but I am reading up on the Zend framework and trying out some tutorials, very useful.. However everything I've read/tried involves the "application/views" and "application/controllers" directories to create views and controllers. I have not yet come across any mention of the "models" subdirectory. Where can I learn more about this and what it's used for? Am I right in assuming that I can build my own functionality (e.g. user login form, CMS) entirely with the concept of a controller and view? (but not a model) Many thanks |
|
|
Re: MVC - where can I learn more about the "model"?On 5/13/08, Rishi Daryanani <rishijd@...> wrote: Hi, The model is just a representation of data, which more often than not means a class with which you retrieve data from the database, i.e. take a look at Zend_Db. Many thanks -- Vincent |
|
|
Re: MVC - where can I learn more about the "model"?A model is usually the layer in the application which holds the data in the application. For instance in your example of a login, a view would have a form, a controller would generate the form & listen to the submission of the form, but the controller would query against the model to see if the user credentials are correct. A very nutshell version.
http://framework.zend.com/manual/en/zend.db.table.html is a good place to start, I actually just wrote up a peice but it covers normalized tables on top of zend_db_table_abstract: http://joshteam.wordpress.com/2008/05/13/zend_db_table-with-normalized-tables/ Hope this helps!
On Tue, May 13, 2008 at 10:41 AM, Rishi Daryanani <rishijd@...> wrote: Hi, |
|
|
Re: MVC - where can I learn more about the "model"?On 5/13/08, Rishi Daryanani <rishijd@...> wrote:
> I have > not yet come across any mention of the "models" > subdirectory. > > Where can I learn more about this and what it's used > for? ZF doesn't have what you may have come to expect as an actual "model" component from other web frameworks. Instead it has Zend_Db and Zend_Db_Table. -- Greg Donald http://destiney.com/ |
|
|
RE: MVC - where can I learn more about the "model"?That's not entirely true. Anything in ZF can be a model at this point.
We will be introducing a model formalism in the future, but we'd like to capture the flexibility that many projects require for their models to do so. Greg is right that the Zend_Db tables are the closest thing we have to a database-backed model. Also consider the fact that you can use full ORM solutions like Propel and Doctrine for your model as well. ,Wil > -----Original Message----- > From: Greg Donald [mailto:gdonald@...] > Sent: Tuesday, May 13, 2008 8:48 AM > To: fw-general@... > Subject: Re: [fw-general] MVC - where can I learn more about the > "model"? > > On 5/13/08, Rishi Daryanani <rishijd@...> wrote: > > I have > > not yet come across any mention of the "models" > > subdirectory. > > > > Where can I learn more about this and what it's used > > for? > > ZF doesn't have what you may have come to expect as an actual "model" > component from other web frameworks. Instead it has Zend_Db and > Zend_Db_Table. > > > -- > Greg Donald > http://destiney.com/ |
|
|
Re: MVC - where can I learn more about the "model"?Less database (RDBMS)-centric - we use Rest and Xmlrpc in the model very often.
Cheers, Till On Tue, May 13, 2008 at 5:58 PM, Wil Sinclair <wil@...> wrote: > That's not entirely true. Anything in ZF can be a model at this point. > We will be introducing a model formalism in the future, but we'd like to > capture the flexibility that many projects require for their models to > do so. > Greg is right that the Zend_Db tables are the closest thing we have to a > database-backed model. Also consider the fact that you can use full ORM > solutions like Propel and Doctrine for your model as well. > > ,Wil > > > > > -----Original Message----- > > From: Greg Donald [mailto:gdonald@...] > > Sent: Tuesday, May 13, 2008 8:48 AM > > To: fw-general@... > > Subject: Re: [fw-general] MVC - where can I learn more about the > > "model"? > > > > On 5/13/08, Rishi Daryanani <rishijd@...> wrote: > > > I have > > > not yet come across any mention of the "models" > > > subdirectory. > > > > > > Where can I learn more about this and what it's used > > > for? > > > > ZF doesn't have what you may have come to expect as an actual "model" > > component from other web frameworks. Instead it has Zend_Db and > > Zend_Db_Table. > > > > |
|
|
Re: MVC - where can I learn more about the "model"?My typical explanation of the Model...
The Model is responsible for maintaining state between HTTP requests in a PHP web application. Any data which must be preserved between HTTP requests is destined for the Model segment of your application. This goes for user session data as much as rows in an external database. It also incorporates the rules and restraints governing that data which is referred to as the "business logic". For example, if you wrote business logic for an Order Model in an inventory management application, company internal controls could dictate that purchase orders be subject to a single purchase cash limit of €500. Purchases over €500 would need to be considered illegal actions by your Order Model (unless perhaps authorised by someone with elevated authority). Models are therefore the logical location for data access but may also act as a central location for examining, verifying and making final manipulations on that data before it's stored, and even after it's retrieved. It really can be anything representing data - database, XML, web services, RSS, CSV files, sessions, etc. The only real constraint is the data is preserved between requests (for PHP at least) Best regards, Paddy
Pádraic Brady
http://blog.astrumfutura.com http://www.patternsforphp.com OpenID Europe Foundation - Irish Representative |
|
|
Re: MVC - where can I learn more about the "model"?I would disagree that the model has to persist. For instance, if I had a website which used a REST service to display data. Maybe YouTube, Flickr, Weather, etc. The REST Service is my model, but it does not persist. At least that's my perspective.
On Tue, May 13, 2008 at 11:10 AM, Pádraic Brady <padraic.brady@...> wrote:
|
|
|
Re: MVC - where can I learn more about the "model"?-- Wil Sinclair <wil@...> wrote
(on Tuesday, 13 May 2008, 08:58 AM -0700): > That's not entirely true. Anything in ZF can be a model at this point. > We will be introducing a model formalism in the future, but we'd like to > capture the flexibility that many projects require for their models to > do so. > Greg is right that the Zend_Db tables are the closest thing we have to a > database-backed model. Also consider the fact that you can use full ORM > solutions like Propel and Doctrine for your model as well. And since nobody else said it: Model !== Database While most web developers consider the two synonyms, this is increasingly false in our current network-enabled world. Web services are more and more often your models -- consider flickr, del.icio.us, S3, Nirvanix, etc. Additionally, your filesystem could be considered a model (this is how we indicate our releases on the Framework site itself), as can config files (I use config files for user management on my personal site), and so on. It is because we recognize that the database and model are not synonymous that we have not yet formalized the Model in our MVC layer. We will likely create a *very* slim interface, likely with simply accessors for attaching a data store and input filters/forms, in upcoming releases; however, we need to determine the value-add of this, and how it would simplify interactions for ZF developers. > > -----Original Message----- > > From: Greg Donald [mailto:gdonald@...] > > Sent: Tuesday, May 13, 2008 8:48 AM > > To: fw-general@... > > Subject: Re: [fw-general] MVC - where can I learn more about the > > "model"? > > > > On 5/13/08, Rishi Daryanani <rishijd@...> wrote: > > > I have > > > not yet come across any mention of the "models" > > > subdirectory. > > > > > > Where can I learn more about this and what it's used > > > for? > > > > ZF doesn't have what you may have come to expect as an actual "model" > > component from other web frameworks. Instead it has Zend_Db and > > Zend_Db_Table. > > > > > > -- > > Greg Donald > > http://destiney.com/ > -- Matthew Weier O'Phinney Software Architect | matthew@... Zend - The PHP Company | http://www.zend.com/ |
|
|
Re: MVC - where can I learn more about the "model"?-- Josh Team <joshteam@...> wrote
(on Tuesday, 13 May 2008, 11:13 AM -0500): > I would disagree that the model has to persist. For instance, if I had a > website which used a REST service to display data. Maybe YouTube, Flickr, > Weather, etc. The REST Service is my model, but it does not persist. At least > that's my perspective. The data in YouTube, Flickr, and Weather persists, though, and those are ultimately your model. :-) > On Tue, May 13, 2008 at 11:10 AM, P draic Brady <padraic.brady@...> > wrote: > > > My typical explanation of the Model... > > The Model is responsible for maintaining state between HTTP requests in a > PHP web application. Any data which must be preserved between HTTP requests > is destined for the Model segment of your application. This goes for user > session data as much as rows in an external database. It also incorporates > the rules and restraints governing that data which is referred to as the > "business logic". For example, if you wrote business logic for an Order > Model in an inventory management application, company internal controls > could dictate that purchase orders be subject to a single purchase cash > limit of 500. Purchases over 500 would need to be considered illegal > actions by your Order Model (unless perhaps authorised by someone with > elevated authority). Models are therefore the logical location for data > access but may also act as a central location for examining, verifying and > making final manipulations on that data before it's stored, and even after > it's retrieved. > > It really can be anything representing data - database, XML, web services, > RSS, CSV files, sessions, etc. The only real constraint is the data is > preserved between requests (for PHP at least) > > Best regards, > Paddy > > > > tfk wrote: > > > > Less database (RDBMS)-centric - we use Rest and Xmlrpc in the model very > > often. > > > > Cheers, > > Till > > > > On Tue, May 13, 2008 at 5:58 PM, Wil Sinclair <wil@...> wrote: > >> That's not entirely true. Anything in ZF can be a model at this point. > >> We will be introducing a model formalism in the future, but we'd like > to > >> capture the flexibility that many projects require for their models to > >> do so. > >> Greg is right that the Zend_Db tables are the closest thing we have to > a > >> database-backed model. Also consider the fact that you can use full ORM > >> solutions like Propel and Doctrine for your model as well. > >> > >> ,Wil > >> > >> > >> > >> > -----Original Message----- > >> > From: Greg Donald [mailto:gdonald@...] > >> > Sent: Tuesday, May 13, 2008 8:48 AM > >> > To: fw-general@... > >> > Subject: Re: [fw-general] MVC - where can I learn more about the > >> > "model"? > >> > > >> > On 5/13/08, Rishi Daryanani <rishijd@...> wrote: > >> > > I have > >> > > not yet come across any mention of the "models" > >> > > subdirectory. > >> > > > >> > > Where can I learn more about this and what it's used > >> > > for? > >> > > >> > ZF doesn't have what you may have come to expect as an actual "model" > >> > component from other web frameworks. Instead it has Zend_Db and > >> > Zend_Db_Table. > >> > > >> > > > > > > > > ----- > P draic Brady > > http://blog.astrumfutura.com > http://www.patternsforphp.com > OpenID Europe Foundation - Irish Representative > -- > View this message in context: http://www.nabble.com/ > MVC---where-can-I-learn-more-about-the-%22model%22--tp17211735p17212335.html > Sent from the Zend Framework mailing list archive at Nabble.com. > > > -- Matthew Weier O'Phinney Software Architect | matthew@... Zend - The PHP Company | http://www.zend.com/ |
|
|
Re: MVC - where can I learn more about the "model"?So if I am pulling a random movie/picture/day/etc. on each http request that persist? The only thing that persist is the request mechanism, not the actual data.
On Tue, May 13, 2008 at 11:19 AM, Matthew Weier O'Phinney <matthew@...> wrote: -- Josh Team <joshteam@...> wrote |
|
|
Re: MVC - where can I learn more about the "model"?I was going to reply the exact same thing ;). A Model needn't be locally persisted - any web service will inevitably be drawing on stored data so in effect it really will be a persisted Model. The number of intervening APIs and sockets is irrelevant.
Paddy
Pádraic Brady
http://blog.astrumfutura.com http://www.patternsforphp.com OpenID Europe Foundation - Irish Representative |
|
|
Re: MVC - where can I learn more about the "model"?Rishi
You're not the first nor the last to be confused by this, but it's actually very simple once you realise it. If you remove views and controller, what's left? Business logic, data and anything specific to your application. Let say you need to represent a user in your system, or a client, those are your models. Often they are persistent in a database, some people even use Zend_Db_Table as a model, but it can be anything, there are no rules of what model is, it's up to you and it will be determined by what you're building. Karol
|
|
|
Re: MVC - where can I learn more about the "model"?Since I have something of a beginner's mind, I will say the most obvious thing of all. Think of the model as modeling some entity out there in the real world, in the conventional sense of the word model. Thus if you were designing a registration system for a veterinary clinic, you might well have models Pet and Owner.
-- David Mintz http://davidmintz.org/ The subtle source is clear and bright The tributary streams flow through the darkness |
|
|
RE: MVC - where can I learn more about the "model"?Here is a little advice for people who want some guidance on creating
their a model layer: NOTE: This is merely a simple example, for guidance only. YMMV. There are a million different ways to do this kind of thing, this is merely one I have found effective. In my apps, I generally create a BaseModel class, from which all others inherit. In this class, I'll define a basic API that I want all models to subscribe to. This is usually something like __get, __set, setDataFromArray, validate (verify data is correct), filter (filter input data), save and other common methods. This setup lets you change the backend storage mechanism easily. If all your model objects use the same API, you can change the underlying storage code of all your models simultaneously and your app is none-the-wiser. An example: Say I begin by using an array to store my data. Suddenly, I realize I want to store my data inside a database. I can change all the methods in my model to set data to a database object. Later in the project, I decide that XML would be a better choice. I can change my methods to write to an XML data file, and once again I don't have to change my application code. You can implement custom behavior by overriding methods and using the 'parent' keyword to call the BaseModel method implementation. In most apps these days, my BaseModel class directly extends Zend_Db_Table_Row. Extending Zend_Db_Table_Row allows my model objects, with all their custom functionality, to be returned directly by Zend_Db_Table function calls. Creating lists is much faster when you don't have to iterate the result set a second time to create model objects from them. I usually won't override the methods I want to use from Zend_Db_Table_Row (__get, __set, setDataFromArray). If I needed to change my storage engine I would implement these methods in my BaseModel to access the new data storage mechanism. In each of my BaseModel subclasses, I'll usually add som |