Jump to content

ZendFramework 2


Guest

Recommended Posts

I don't want this thread to turn in to a "Let's burn ZendFramework 2, be a hipster".  I'd like constructive answers with this topic since there are a number of questions I have,  I'd love to understand how to implement ZendFramework 2 in a simple, logical way.

 

 

To start, I have downloaded the ZendFramework 2, and immediately I was asked to use composer to install it, except, I hate Composer.  Instead I created the following structure:

/app/
    /config/
    /data/
    /module/
    /vendor/
        /DoctrineOrm/
        /Zend/
/public/

I then installed the Skeleton Application, this was following the examples on the ZF documentation.  I don't like creating php files that look like this:

<?php

return array(
    // Associative array of values; returned by executable php file.
);

I don't agree with php scripts, that return associative arrays, in my opinion, configuration files should be plain text only, and should not be available to `include_once` or `require_once`.

 

So after looking at the ZendFramework 2 documentation; they suggest the following:

<?php

// Define the existing working directory.
chdir(dirname(__DIR__));

// Should composer not be used (because it's not useful at all).
require 'init_autoloader.php';

// Finally Zends' idea of application code.
Zend\Mvc\Application::init(require '../config/application.config.php')->run();

1.  I don't like the idea of the following;  "init(require '../config/application.config.php')"; I would expect to simply load a config file, and parse it as the argument.

 

2.  I would much prefer to use the "Zend\Config\Reader\Ini" class and parse an INI type config file.

 

 

Another problem, I would like to implement an application, that isn't using the Skeleton Application.  This is because, I don't like the "Module.php" class, and the large "<modulename>.config.php" config file.  I don't like routes looking like the following:

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'App\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            // The following is a route to simplify getting started creating
            // new controllers and actions without needing to create a new
            // module. Simply drop new controllers in, and you can access them
            // using the path /app/:controller/:action
            'application' => array(
                'type'    => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/app',
                    'defaults' => array(
                        '__NAMESPACE__' => 'App\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        ),
    ),
    'translator' => array(
        'locale' => 'en_US',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'App\Controller\Index' => 'App\Controller\IndexController'
        ),
    ),
    'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'application/index/index' => __DIR__ . '/../view/app/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
);

Again, a configuration file that looks like that is completely ridiculous, it's just stupid having to type all of that out.  How would this be configured using an INI type file?

 

I would like to understand, how can I use the ZendFramework 2, as a library of classes without all the overload, bloat and unnecessary configurations?  How can I implement an application level of classes (controllers, forms, views and models) as well as modules?  Are there any examples someone could potentially share?

 

Preferably, not using composer, or the Zend Skeleton Application.  Otherwise, is there another framework that could be suggested? (excluding the likes of; FuelPHP; CakePHP; CodeIgniter; YII; Laravel).

Link to comment
Share on other sites

If you don't want to work within the confinements of the framework you are using you are really going to need to investigate this stuff yourself.

 

I completely understand where you are coming from (except the composer part - this truly is an awesome tool), as in a lot of cases, skeleton apps do not fit your normal workflow. The problem is, that most frameworks require a certain amount of convention. This is how they make application development "rapid". The framework needs to kno wwhere everything lives and expects things to be configured accordingly.

 

Some frameworks however are more configuration over convention out of the box. This gives you the flexibility to configure the conventions used by the framework.

 

We have just spent the past 4 months bending Laravel into a shape that was right for us. We now have our own structure / skeleton.

 

Unfortunately however, this stuff isn't usually documented anywhere, and if it was, it would be describing someone else's workflow which is precisely what your trying to avoid.

 

There are other, more minimal frameworks around however that will allow you to make these sorts of changes more easily. Silex comes to mind. It is a very small framework built on the shoulder of Symfony2.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.