Sorry but what is included in the zip file?
i have a simple file inside called, demo...
what is it?
This tutorial is not relevant anymore, please read this post.
This is how I bootstrap my applications with Zend_Application included in the ZF 1.8 beta release.
This is not realy a tutorial because I'm not going explain everything, if any of my comments are unclear, don't hesitate to ask.
directory structure
[HTML]
/application
/forms
/layouts
/scripts
/layout.php
/models
/modules
/default
/ErrorController.php
/IndexController.php
/tables
/views
/default
/scripts
/error
/error.php
/index
/index.php
/library
/My
/Application
/Resource
/Bootstrap.php
/Controller
/Action.php
/Zend
/...
/public
/css
/img
/.htaccess
/index.php
[/HTML]
/public/index.php
[PHP]
// Define the absolute path to our root folder
define('BASE_PATH', dirname(dirname(__FILE__)));
// Define the absolute path to our application folder
define('APP_PATH', BASE_PATH . '/application');
// This namespace is part of the application structure, which is included in path defenitions below
define('APP_NS', 'My');
// Set our application environment
define('APP_ENV', 'development');
// Add the library folder to PHP's include path
set_include_path(
BASE_PATH . '/library'
. PATH_SEPARATOR .
get_include_path()
);
// Include the autoloader
require_once 'Zend/Loader/Autoloader.php';
// Register autoloading
$autoloader = Zend_Loader_Autoloader::getInstance();
// Add namespace to autoload
$autoloader->registerNamespace(APP_NS . '_');
// This will show warnings if the file can not be found by
// the autoloader which is very usefull for development
$autoloader->suppressNotFoundWarnings(false);
// We are creating our own resources (like models and stuff)
// Define a path to those resources (I've used the namespace as our.. namespace...)
$resourceloader = new Zend_Loader_Autoloader_Resource(array(
'namespace' => APP_NS . '_',
'basePath' => APP_PATH
));
// Here we are adding the resource types, the path where to find them and the namespace to use
// for example to load a model we use: $user = new My_Model_User()
$resourceloader->addResourceType('Form', 'forms', 'Form');
$resourceloader->addResourceType('Model', 'models', 'Model');
$resourceloader->addResourceType('Table', 'tables', 'Table');
// We are using models as our default resource type
$resourceloader->setDefaultResourceType('Model');
// We need to pass the file and the class of the bootstrap
$application = new Zend_Application(APP_ENV);
$application->setBootstrap(
APP_NS . '/Application/Bootstrap.php',
APP_NS . '_Application_Bootstrap'
);
// We want to add some of our plugins to we need to get our bootstrap back
$bootstrap = $application->getBootstrap();
// We've created some plugins that we need to add to the bootstrap
$bootstrap->registerPluginResource(new My_Application_Resource_View());
$bootstrap->registerPluginResource(new My_Application_Resource_Frontcontroller());
// You create as much resources as you want, for example: Zend_Db, Zend_Layout, Zend_Config, Zend_Auth....
// Bootstrap, and finaly run our application
$application->bootstrap();
$application->run();
[/PHP]
References
Zend_Loader_Autoloader
Zend_Loader_Autoloader_Resource
Zend_Application
I've provided an application template for download. (not including ZF 1.8)
Last edited by Regx; 05-13-2009 at 11:43 AM. Reason: outdated information
Sorry but what is included in the zip file?
i have a simple file inside called, demo...
what is it?
Its a directory structure like above
/application
/forms
/layouts
/scripts
/layout.php
/models
/modules
/default
/ErrorController.php
/IndexController.php
/tables
/views
/default
/scripts
/error
/error.php
/index
/index.php
/library
/My
/Application
/Resource
/Bootstrap.php
/Controller
/Action.php
/Zend
/...
/public
/css
/img
/.htaccess
/index.php
Hi
Bootstrapping a zf project is pretty easy if you follow the Quick Start Zend put out. Zend Framework
If you have a preexiting project use this link:
Zend Framework: Documentation
www.armando.ws
Author: Beginning Zend Framework
I used the 1.8 Beta version here and there has been a lot of changes in bootstrapping since the final release came out.
If you read this thread because you dont know how to boostrap your project, I would advice you to check out the Quickstart and the Zend_Application Reference.
Regx.
Thanks regx, for your explanation it's very usefull.
But I'm afraid because it's the second time I use Zend and I'm feeling like I was starting all over again and spend to much time to set the basics things like session, translate, etc.
I want to use the new Zend 1.8.1 with the new Application and Boostrap class but this is so much work searching how it works. I think I have a lack of understanding the MVC concept.
The Zend doc doesn't help me. Do you have any tips to master a framework ?
Cheers,
Did you read the Quickstart and Zend_Application. Or search for some guides about MVC, you can find them anywhere...
If I can't figure it out, I browse the code until I know exactly how it works
Btw, I know how it feels to start all over again![]()
Bootstrapping (for example adding modules) is becoming more complex and all this complexity will work against Zend Framework. Let be honest to learn how to use even the ordinary Zend_Application is a lot of time consuming (and i am not talking here about all the bugs in it) and i am afraid that not many people have such time to spend.
I am afraid that Zend Framework is becoming a scientific project than an usable one where many smart people are trying to implement many smart ideas and by doing this are increasing the complexity to a not usable point.
When i choose a framework i have limited time and usually i don't want to make rocket science applications. Is good to learn the patterns but now more then ever the ZF force me to learn all inside mechanics (when this should be hidden) to be able to use it. And this behavior is against the idea of a framework.
Actually ZF was designed as robust enterprise level framework, and complexity one thing that you can't avoid.. it will only get bigger, not smaller..
As far as Zend_Aplication goes, no one force you to use it and that the true power of ZF - you can use only parts of framework that you really need. On the other hand Zend_Aplication provides nice api for robust modules witch requires their own bootstraping, configuration, etc..
Try implement same smart idea into CakePHP and then you will see how simple it is
Then you have chosen a wrong framework for your projects, because ZF isn't build for small cms-like projects but for something much more bigger..
And btw: you should know what framework is doing in every moment of request process and what classes and methods are invoked.