Domanda

I am currently struggling with a proper approach with how to organize mobile views within my project structure. Currently I am using the zend framework and have the recommended structure:

 application/
    controllers/
    models/
    modules/
        module1/
           controllers/
           views/
        module2/
           controllers/
           views/
    views/
        filters/
        helpers/
        scripts/
    Bootstrap.php

I am considering using the approach suggested here. However I would append my path to my views to be a subfolder rather than append for a level up so that the structure looks like:

 application/
    controllers/
    models/
    modules/
        module1/
           controllers/
           views/
                mobile/
        module2/
           controllers/
           views/
                mobile/
    views/
        mobile/
        filters/
        helpers/
        scripts/
    Bootstrap.php

However I am not familiar with zend enough to know how to have a dynamic path to my views.

 $viewPath = "/views";
 if($is_mobile) {
       $viewPath .= "/mobile";
 }
 //render dynamic $viewPath here.

Would this code go in the front controller or is this something better suited for the application.ini? Is there a specific function for setting paths to views folder in zend like setControllerDirectory()?

È stato utile?

Soluzione

You can map views directly in your module.config, rather than trying to get Zend to do it automatically:

'view_manager' => array(
    'template_map' => array(
        'layout'    => __DIR__ . '/../view/layout/layout.phtml',
        'index'     => __DIR__ . '/../view/root/index/index.phtml',
        '404'       => __DIR__ . '/../view/error/404.phtml',
        '500'       => __DIR__ . '/../view/error/index.phtml',
        'some_view'  => __DIR__.'/relative_path_from_module_config_to_your_directory/view.phtml'
    ),

Then, in your controller you can choose which view to use:

    $view = new \Zend\View\Model\ViewModel($data);
    $view->setTemplate('some_view'); //name of view in the template_map
    return $view;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top