2010年11月26日星期五

Re: [fw-mvc] Re: How to instantiate a model class to use its functions, standard solution?

Hi Wil,

Thanks for your mail. I have a few comments, hope you can help me out.

a) Bootstrap - in the quick start this mentions that Bootstrap can be a class,
but my current file is 'normal' php code, no class involved. I know its better
to have a class, but since we used Zend Framework back in 2008 (and recently
upgraded), our bootstrap.php code has not changed to use a class and our site is
working fine ok with our own custom functions as explained. Do you see any
issues with this approach or is it easy to switch to a class, or at least move
some of the common code to a class? I suppose I need to read more on this to
understand, however it isn't as pressing as my points below for now.

b) http://framework.zend.com/manual/en/learning.quickstart.create-model.html - I
read through this before posting and I re-read it again, I understand some of
the concepts but not all of them. I understand a number of items require us to
execute commands from the command line, however for my interest - I usually load
data into a database from my own custom PHP script or via an admin interface
(e.g. phpPgAdmin for Postgresql) if need be. Is there a certain advantage of
doing the database updating/data upload in a similar way described in the above
link? I suppose the advantage is that it keeps everything together, within the
application/framework.


c) One thing I don't understand about the above is, why do we have two models:
Application_Model_GuestbookMapper
and
Application_Model_Guestbook
I understand the former uses the database, and the latter doesn't, so since they
perform somewhat different tasks, it is better to separate them as two models
rather than one larger model?

d) Following the above tutorial I did try to create a
"Application_Model_Guestbook" model, however what I did not do is execute the
command line code like % zf create model Guestbook.
I suppose this was the problem, because my script kept returing the error that
the php file was not found in /Application/Model/ - I'm not sure why it was
looking in that directory; I thought the default for the above would be
/application/models/ (case sensitive / Apache). I'm sure I must have missed a
configuration step but I was just experimenting with the defaults and how to do
all this by php code / bootstrap.php alone. Finally I understood that I need to
set up a new Zend_Loader_Autoloader_Resource and that worked.

e) http://framework.zend.com/manual/en/learning.quickstart.create-form.html -
this is interesting as I have always put direct HTML form code in my view, and
processed/validated the data in the controller. This worked well for me, but I'm
curious, must I execute those command line codes again or can I dive straight
into creating code like the following?
// application/forms/Guestbook.php
class Application_Form_Guestbook extends Zend_Form

I suppose for the above, it requres an update to bootstrap.php again on the
Resource loader to point the application to the /forms/ directory? If its really
simple and I could have the code for that it'd be great :)

f) My final, big question. I have a products list page, which displays lots of
products - but the Products List isn't really a "model", it is more a list of
Products (while a Product can be classified as a model) - it is complicated by
various scenarios so I have lots of small functions that are specific to the
Product List page, such as filters, ranges, product types (filter again),
sale/non-sale mode, etc. If *you* were coding a products list page, would you :
- simply create many controller auxiliary/helper functions to do the job
- or set up a products list model to hold the functions
- or set up a unique class (similar to a model, except we won't *call* it a
model) and store it anywhere in a common directory, even models/commonclasses/
or something like that?

Any response to any of these questions would help, but my most pressing question
if question f) above.

Many thanks,
Rishi


________________________________
From: Wil Moore III <wil.moore@wilmoore.com>
To: fw-mvc@lists.zend.com
Sent: Wed, November 24, 2010 12:28:44 AM
Subject: [fw-mvc] Re: How to instantiate a model class to use its functions,
standard solution?


Rishi,

Have you tried the quick start guide?
http://framework.zend.com/manual/en/learning.quickstart.create-project.html

I suspect many of your questions will be answered after going through this.

BTW, the "My" namespace is contrived for example purposes -- not saying you
can't use it; however, there is nothing compulsory about it.

Also, anytime you get errors regarding a not found file (class), you can
start by checking that the file is within the include path (the include path
will generally be echo'd in the error/exception output). There can be more
to it if you are autoloading, but generally, you can at least start here.

Please post again after going attempting some of the concepts presented in
the quick start guide.

-----
--
Wil Moore III

Why is Bottom-posting better than Top-posting:
http://www.caliburn.nl/topposting.html
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/How-to-instantiate-a-model-class-to-use-its-functions-standard-solution-tp3054833p3056023.html

Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: