Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework General discussions > Resources for Developers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-2009, 01:57 PM
Junior Member
 
Join Date: Apr 2009
Location: The Netherlands
Posts: 9
Send a message via MSN to Regx
Post Bootstrapping, the ZF 1.8 way

Quote:
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)
Attached Files
File Type: zip demo.zip (6.3 KB, 94 views)

Last edited by Regx; 05-13-2009 at 11:43 AM. Reason: outdated information
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-29-2009, 02:45 PM
Junior Member
 
Join Date: Oct 2007
Posts: 2
Default

Sorry but what is included in the zip file?
i have a simple file inside called, demo...
what is it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-04-2009, 09:14 PM
Junior Member
 
Join Date: Sep 2008
Posts: 6
Default

Its a directory structure like above

Quote:
/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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-05-2009, 12:34 AM
Member
 
Join Date: Nov 2008
Location: San Jose
Posts: 32
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-13-2009, 11:38 AM
Junior Member
 
Join Date: Apr 2009
Location: The Netherlands
Posts: 9
Send a message via MSN to Regx
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-26-2009, 10:31 AM
Junior Member
 
Join Date: May 2009
Posts: 1
Default

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,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-26-2009, 04:03 PM
Junior Member
 
Join Date: Apr 2009
Location: The Netherlands
Posts: 9
Send a message via MSN to Regx
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-29-2009, 08:12 AM
Junior Member
 
Join Date: May 2009
Posts: 13
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-29-2009, 09:58 AM
Senior Member
 
Join Date: Sep 2008
Location: Croatia
Posts: 356
Send a message via MSN to Eugen
Default

Quote:
Originally Posted by BornForCode View Post
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.
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..

Quote:
Originally Posted by BornForCode View Post
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.
Try implement same smart idea into CakePHP and then you will see how simple it is

Quote:
Originally Posted by BornForCode View Post
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.
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 06:08 PM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0