cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR] Specify the path to the main layout and partials

Open nikolasha opened this issue 13 years ago • 5 comments

Do, please, methods to specify a path to the main layout and partials of object View.

<?php

namespace Phalcon\Mvc;

class View extends \Phalcon\DI\Injectable
{
    // ...
    public function setLayoutsDir($layoutsDir)
    {
        $this->_layoutsDir = (string) $layoutsDir;
    }

    public function setPartialsDir($partialsDir)
    {
        $this->_partialsDir = (string) $partialsDir;
    }
    // ...
}

nikolasha avatar Dec 10 '12 17:12 nikolasha

In his project I use a directory structure views:

/app/views                            - base path of views
/app/views/layouts/main.phtml         - main layout of page
/app/views/partials/header.phtml      - layout header of page
/app/views/partials/footer.phtml      - layout footer of page
/app/views/contents/index.phtml       - layout of IndexController
/app/views/contents/index/index.phtml - view of IndexController::indexAction

I had to write an extension for your class \Phalcon\Mvc\View

P.S. Sorry for my english ;)

nikolasha avatar Dec 11 '12 12:12 nikolasha

That is interesting :)

Do you mind sharing your implementation in the incubator?

https://github.com/phalcon/incubator

niden avatar Dec 11 '12 14:12 niden

I suggest following structure:

 /app/views                    
 /app/layouts/                                               // Layouts and Partials
 /app/layouts/main.phtml               
 /app/layouts/header.phtml      
 /app/layouts/footer.phtml      
 /app/views/contents/index.phtml       
 /app/views/index.phtml`

salarmehr avatar Dec 14 '12 16:12 salarmehr

This is a good option, but not /app/views/contents/index.phtml, and the /app/views/index/index.phtml Only the directory layout I did a little bit differently:

/app/layouts/                    - layouts and partials
/app/layouts/main.phtml          - main layout of page
/app/layouts/main/header.phtml
/app/layouts/main/footer.phtml
/app/layouts/mobile.phtml        - main layout of the mobile version
/app/layouts/mobile/header.phtml
/app/layouts/mobile/footer.phtml
<!-- /app/layouts/main.phtml -->

<!DOCTYPE html>
<html>
<body>
    <?= $this->partial('main/header.phtml') ?>
    <?= $this->content() ?>
    <?= $this->partial('main/footer.phtml') ?>
</body>
</html>

I will try to write an extension for this option. Only standard class Phalcon\Mvc\View badly expands - continuous hard code :(

nikolasha avatar Dec 14 '12 23:12 nikolasha

This was addressed in 0.8.0

ghost avatar Dec 21 '12 02:12 ghost