+ Reply to Thread
Results 1 to 9 of 9

Thread: Bootstrapping, the ZF 1.8 way

  1. #1
    Regx is offline Junior Member
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    9

    Post Bootstrapping, the ZF 1.8 way

    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
    Last edited by Regx; 05-13-2009 at 11:43 AM. Reason: outdated information

  2. #2
    boardmain is offline 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?

  3. #3
    Themodem is offline Junior Member
    Join Date
    Sep 2008
    Posts
    8

    Default

    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

  4. #4
    armandop is offline Member
    Join Date
    Nov 2008
    Location
    San Jose
    Posts
    35

    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

  5. #5
    Regx is offline Junior Member
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    9

    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.

  6. #6
    damienS is offline 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,

  7. #7
    Regx is offline Junior Member
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    9

    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

  8. #8
    BornForCode is offline 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.

  9. #9
    Eugen is offline Senior Member
    Join Date
    Sep 2008
    Location
    Croatia
    Posts
    400

    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.

+ Reply to Thread

Similar Threads

  1. 1.8.0 Bootstrapping Modules and Autoloaders
    By leigh_m in forum General Q&A on Zend Framework
    Replies: 12
    Last Post: 07-30-2010, 05:23 PM
  2. Bootstrapping configurationless application resource
    By carolx0 in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 06-11-2010, 01:05 PM
  3. Bootstrapping new project - need well-versed ZF/JQuery dev
    By maxalex in forum Paid work offers and requests
    Replies: 0
    Last Post: 11-05-2009, 08:21 PM
  4. Modules, Forms, and Maybe Bootstrapping
    By Bateman in forum General Q&A on Zend Framework
    Replies: 3
    Last Post: 07-28-2009, 11:46 PM
  5. Strange bootstrapping problem
    By Sh4wn in forum General Q&A on Zend Framework
    Replies: 3
    Last Post: 06-30-2009, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts