About findLayoutTemplateFile() and setLayout() methods on windows and linux. UPDATED problem on nette 2.3.2

4 years ago

alnux
Member | 106
+
0
-

Ok i had an issue becouse i develop on windows but after i upload to linux server and it get me this problem, the case is that i have the next ditrctory structure

--app
----backend
----common
------templates
--------@layout.latte
----front

I wanted all modules call @layout.latte from common/template directory, all was goood on windows but on linux does not find the layout including doing tpr's sugestion. so i decided find why it was working on windows and not on linux, the answear was that on linux as you know is more strict with all and findLayoutTemplateFile() returns the next paths

array (4)
0 => "/home/cvpbsjbn/app/front/templates/BO/Index/@layout.latte" (57)
1 => "/home/cvpbsjbn/app/front/templates/Index/@layout.latte" (54)
2 => "/home/cvpbsjbn/app/front/templates/Index.@layout.latte" (54)
3 => "/home/cvpbsjbn/app/front/templates/@layout.latte" (48)
array (5)
0 => "/home/cvpbsjbn/app/front/templates/BO/Index/@layout.latte" (57)
1 => "/home/cvpbsjbn/app/front/templates/Index/@layout.latte" (54)
2 => "/home/cvpbsjbn/app/front/templates/Index.@layout.latte" (54)
3 => "/home/cvpbsjbn/app/front/templates/@layout.latte" (48)
4 => "/home/cvpbsjbn/app/templates/@layout.latte" (42)

if you see the app is trying to find layout from front module

and if i put parent directory(diferent presenter) that are static it will never find it (i dont know how on windows find it)

array (4)
0 => "/home/cvpbsjbn/app/common/templates/BO/Sign/../../../../common/templates/@layout.latte" (86)
1 => "/home/cvpbsjbn/app/common/templates/Sign/@../../../../common/templates/@layout.latte" (84)
2 => "/home/cvpbsjbn/app/common/templates/Sign.@../../../../common/templates/@layout.latte" (84)
3 => "/home/cvpbsjbn/app/common/templates/@../../../../common/templates/@layout.latte" (79)
array (5)
0 => "/home/cvpbsjbn/app/common/templates/BO/Sign/../../../../common/templates/@layout.latte" (86)
1 => "/home/cvpbsjbn/app/common/templates/Sign/@../../../../common/templates/@layout.latte" (84)
2 => "/home/cvpbsjbn/app/common/templates/Sign.@../../../../common/templates/@layout.latte" (84)
3 => "/home/cvpbsjbn/app/common/templates/@../../../../common/templates/@layout.latte" (79)
4 => "/home/cvpbsjbn/app/templates/@../../../../common/templates/@layout.latte" (72)

making a few modifications on findLayoutTemplateFile() and setLayout() and adding a private var $staticLayout to presenter

/**
 * Complete and static dir to layout
 * @var bool
 */
private $staticLayout;

/**
* Changes or disables layout.
* @param  string|FALSE
* @return self
*/
public function setLayout($layout, $staticpath = FALSE)
{
    $this->staticLayout = $staticpath;
    $this->layout = $layout === FALSE ? FALSE : (string) $layout;

    return $this;
}

/**
  * Finds layout template file name.
  * @return string
  * @internal
 */
public function findLayoutTemplateFile()
{
    if ($this->layout === FALSE) {
        return;
    }

    if($this->staticLayout === FALSE) {
        $files = $this->formatLayoutTemplateFiles();

        foreach ($files as $file) {
            if (is_file($file)) {
                return $file;
            }
        }
    }
    else {
        if (is_file($this->layout)) {
            return $this->layout;
        }
    }


    if ($this->layout) {
        $file = preg_replace('#^.*([/\\\\].{1,70})\z#U', "\xE2\x80\xA6\$1", reset($files));
        $file = strtr($file, '/', DIRECTORY_SEPARATOR);
        throw new Nette\FileNotFoundException("Layout not found. Missing template '$file'.");
    }
}

with this works fine becouse the the layout finder search a specific file instead a particular layout of each module

UPDATED: this problem is on nette framework 2.3.2

Last edited by alnux (2015-05-18 17:13)