I've been using Zend Framework in a somewhat 'partial' way between Zend's MVC
logic and our own coding structure (classes and shared functions). This has
been done using controllers and views, with the controller doing most of the
work (as opposed to the model). We have a new feature which required shared
functions again, and I'd like to put these in its own class which can be
instantiated when needed - ie. a model. (I'd like to do this to learn how to
code a model, for my own reference and better coding for the future).
The model needs to simply be a class with a few functions. It does not need to
extend Zend_Db or anything (as we are currently using our own functions for
database management) but it would be nice for it to set variables in
$this->controller.
My simple question - if I put the model in the 'application/models/' folder can
call it say 'ProductList.php' - how do I update bootstrap.php to set the
filepath to this model? Or do I need to include the file explicitly in the
controller? I can't seem to find a simple guide online for this.
FYI, my current bootstrap.php file contains the following, on Zend Framework
version 1.10.2 (recently upgraded from an older version):
/* Add the Zend Framework library to the include path so that we can access the
ZF classes */
set_include_path('../library' . PATH_SEPARATOR . get_include_path());
/* Set up autoload so we don't have to explicitely require each Zend Framework
class */
include_once('Zend/Loader/Autoloader.php');
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);
Online references show that the autoloader in bootstrap is more efficient than
doing an explicit include -
- I just want to know typically what/how you would name and instantiate a model?
Or do I need to go about this another way?
- I assume the solution to the above is very simple, so I'd just need to
know\understand the code to use to do this.
- Note that references like the below show bootstrap "classes", but our current
bootstrap.php file has code straightaway like the above, and not in a class.
References so far:
http://devzone.zend.com/article/4525-Developing-a-Comprehensive-Autoloader
http://framework.zend.com/manual/en/zend.loader.autoloader.html - good for
function references
http://www.youtube.com/watch?v=kuNNwpeNn4s
http://techblog.wimgodden.be/2008/12/21/autoloading-in-zend-framework-how-not-to-do-it/
Many thanks
Rishi
没有评论:
发表评论