Aura.View Twostep View

49 views
Skip to first unread message

guillaume ferrand

unread,
Feb 3, 2014, 4:30:09 PM2/3/14
to aur...@googlegroups.com
Hi,

I cant figure how to set Paths for layout and views in Aura.View v2.

Can someone give me a hint on the way to do it properly ?


Hari K T

unread,
Feb 3, 2014, 5:39:49 PM2/3/14
to aur...@googlegroups.com

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt


--
You received this message because you are subscribed to the Google Groups "The Aura Project for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

guillaume ferrand

unread,
Feb 6, 2014, 10:18:43 AM2/6/14
to aur...@googlegroups.com
Yes that's what I figured already but i have to admit that I'm pretty lost on the way to achieve this.

First, I wanted to define all this in config/define.php (like i used to do with Aura.View v1) but i couldn't get a way to do it. (No big deal for now, so I go on with my main problem right now : having a view file that is being used and displayed)

Let me explain what I did if you can help me to sort things out.

Right now I have an AbstractController which extends Aura.View.Manager

In this AbstractController I have this :
        $view_finder = $this->getViewFinder();
        $view_finder->setPaths([
            'Fli\Dashboard' => dirname(__DIR__) . '/Views',
        ]);

Then, I have a DummyController which extends my AbstractController which is a test controller for displaying my first view but...

In my DummyController action, i have this : 
print_r($this->getViewFinder()->getPaths());
which displays : 
Array ( [\Fli\Dashboard\] => /var/www/fl-dashboard/src/Fli/Dashboard/Views/ ) 

My file system is ok with this path :
trololo:~# ll /var/www/fl-dashboard/src/Fli/Dashboard/Views/
total 4
-rwxrw---- 1 wwwdev www-data 96 janv. 31 08:53 test.php

after the print_r, i have the following code : 
$data = [
     'name' => 'Ferrand',
     'email' => 'f...@example.com',
];
$output = $this->render($data, 'test');  // i tried test.php too

this results in :
Exception 'Aura\View\Exception\TemplateNotFound' thrown for GET / Params: array ( 'controller' => 'dummy', 'action' => 'main', ) exception 'Aura\View\Exception\TemplateNotFound' with message 'test' in /var/www/fl-dashboard/vendor/aura/view/src/Template.php:56 Stack trace: #0 /var/www/fl-dashboard/vendor/aura/view/src/Template.php(26): Aura\View\Template->convertToClosure('test') #1 /var/www/fl-dashboard/vendor/aura/view/src/Manager.php(164): Aura\View\Template->render('test') #2 /var/www/fl-dashboard/src/Fli/Dashboard/Controller/DummyController.php(38): Aura\View\Manager->render(Array, 'test') #3 [internal function]: Fli\Dashboard\Controller\DummyController->main() #4 /var/www/fl-dashboard/vendor/aura/dispatcher/src/InvokeMethodTrait.php(96): ReflectionMethod->invokeArgs(Object(Fli\Dashboard\Controller\DummyController), Array) #5 /var/www/fl-dashboard/vendor/aura/dispatcher/src/Dispatcher.php(111): Aura\Dispatcher\Dispatcher->invokeMethod(Object(Fli\Dashboard\Controller\DummyController), 'main', Array) #6 /var/www/fl-dashboard/vendor/aura/dispatcher/src/Dispatcher.php(124): Aura\Dispatcher\Dispatcher->dispatch(Object(Fli\Dashboard\Controller\DummyController), Array) #7 /var/www/fl-dashboard/vendor/aura/dispatcher/src/Dispatcher.php(90): Aura\Dispatcher\Dispatcher->dispatch(Object(Aura\Di\LazyNew), Array) #8 /var/www/fl-dashboard/vendor/aura/web-kernel/src/WebKernelDispatcher.php(49): Aura\Dispatcher\Dispatcher->__invoke(Array) #9 /var/www/fl-dashboard/vendor/aura/web-kernel/src/WebKernel.php(45): Aura\Web_Kernel\WebKernelDispatcher->__invoke() #10 /var/www/fl-dashboard/web/index.php(28): Aura\Web_Kernel\WebKernel->__invoke() #11 {main}


Any hint ?

I know Aura.View v2 is still in development but Documentation is a bit straightfoward (only mentionning closures) and even if I read a lot of Aura code, i can't really get exactly why the Finder object can't get my view.

What did I miss ?

Hari K T

unread,
Feb 6, 2014, 10:45:49 AM2/6/14
to aur...@googlegroups.com
Seems you missed to set the paths to layout.

See view.php https://gist.github.com/harikt/8841225

I can send more information, if needed at sometime if needed. ( Bit busy )

Thanks

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt


guillaume ferrand

unread,
Feb 6, 2014, 11:45:48 AM2/6/14
to aur...@googlegroups.com
I thought the layout as not mandatory according to the doc but i've added it.

Even with the layout, it still cant find the files :
Exception 'Aura\View\Exception\TemplateNotFound' thrown for GET / Params: array ( 'controller' => 'dummy', 'action' => 'main', ) exception 'Aura\View\Exception\TemplateNotFound' with message 'inner' in /var/www/fl-dashboard/vendor/aura/view/src/Template.php:56 Stack trace: #0 /var/www/fl-dashboard/vendor/aura/view/src/Template.php(26): Aura\View\Template->convertToClosure('inner') #1 /var/www/fl-dashboard/vendor/aura/view/src/Manager.php(164): Aura\View\Template->render('inner') #2 /var/www/fl-dashboard/src/Fli/Dashboard/Controller/DummyController.php(42): Aura\View\Manager->render(Array, 'inner', 'outer') #3 [internal function]: Fli\Dashboard\Controller\DummyController->main() #4 /var/www/fl-dashboard/vendor/aura/dispatcher/src/InvokeMethodTrait.php(96): ReflectionMethod->invokeArgs(Object(Fli\Dashboard\Controller\DummyController), Array) #5 /var/www/fl-dashboard/vendor/aura/dispatcher/src/Dispatcher.php(111): Aura\Dispatcher\Dispatcher->invokeMethod(Object(Fli\Dashboard\Controller\DummyController), 'main', Array) #6 /var/www/fl-dashboard/vendor/aura/dispatcher/src/Dispatcher.php(124): Aura\Dispatcher\Dispatcher->dispatch(Object(Fli\Dashboard\Controller\DummyController), Array) #7 /var/www/fl-dashboard/vendor/aura/dispatcher/src/Dispatcher.php(90): Aura\Dispatcher\Dispatcher->dispatch(Object(Aura\Di\LazyNew), Array) #8 /var/www/fl-dashboard/vendor/aura/web-kernel/src/WebKernelDispatcher.php(49): Aura\Dispatcher\Dispatcher->__invoke(Array) #9 /var/www/fl-dashboard/vendor/aura/web-kernel/src/WebKernel.php(45): Aura\Web_Kernel\WebKernelDispatcher->__invoke() #10 /var/www/fl-dashboard/web/index.php(28): Aura\Web_Kernel\WebKernel->__invoke() #11 {main}


In my controller i have the following code: (in bold)
print_r($this->getLayoutFinder()->getPaths());
displays : Array ( [\0\] => /var/www/fl-dashboard/src/Fli/Dashboard/Layout/ )
in file system : ll /var/www/fl-dashboard/src/Fli/Dashboard/Layout/
total 4
-rwxrw---- 1 wwwdev www-data 192 f�vr.  6 11:09 outer.php

print_r($this->getViewFinder()->getPaths());
displays : Array ( [\0\] => /var/www/fl-dashboard/src/Fli/Dashboard/View/ ) 
in file system : trololo:/var/www/fl-dashboard/src/Fli/Dashboard# ll /var/www/fl-dashboard/src/Fli/Dashboard/View/
total 4
-rwxrw---- 1 wwwdev www-data 96 janv. 31 08:53 inner.php

$data = [
    'name' => 'Ferrand',
    'email' => 'f...@example.com',
];

$view_template = 'inner';
$layout_template = 'outer';

$output = $this->render($data, $view_template, $layout_template);

echo $output;

If I put a closure in both $view_template and $layout_template it's working as expected but with file names, it's still exactly the same problem

Any thoughts ?



FYI in your view.php, you have an error in the setPaths which triggers: 
Argument 1 passed to Aura\View\Finder::setPaths() 

$view_manager->getLayoutFinder()->setPaths(__DIR__ . '/template/');
$view_manager->getViewFinder()->setPaths(__DIR__ . '/template/');

should be

$view_manager->getLayoutFinder()->setPaths([__DIR__ . '/template/']);
$view_manager->getViewFinder()->setPaths([__DIR__ . '/template/']);

Hari K T

unread,
Feb 7, 2014, 6:37:10 AM2/7/14
to aur...@googlegroups.com
That is an interesting one.

I am not sure when did the changes happened though.

So currently the below way will work .

$view_manager->getViewFinder()->setName('inner', __DIR__ . '/template/inner.php');
$view_manager->getLayoutFinder()->setName('outer', __DIR__ . '/template/outer.php');

Gist updated https://gist.github.com/harikt/8841225

I want to see how it can be used with classes. Not sure on that.

Thank you.

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt


Hari K T

unread,
Feb 7, 2014, 7:38:12 AM2/7/14
to aur...@googlegroups.com
another way is set the paths and set the prefixes.

But I am not sure the idea of prefixes.

$view_manager->getViewFinder()->setPaths(array('something' => __DIR__ . '/template/'));
$view_manager->getViewFinder()->setPrefixes(array('something'));
$view_manager->getLayoutFinder()->setPaths(array('something' => __DIR__ . '/template/'));
$view_manager->getLayoutFinder()->setPrefixes(array('something'));

And to me Aura.View still has some works in mind by Paul. Hopefully he will be able to address things.

Thank you.

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt


guillaume ferrand

unread,
Feb 10, 2014, 4:31:27 PM2/10/14
to aur...@googlegroups.com
Thank you for the help

this works good : $view_manager->getViewFinder()->setName('inner', __DIR__ . '/template/inner.php');

Yet, the layout part doesnt trigger any error but is not rendered at all after render() is called : I only get the inner view.  (called with $this->render($data, $view_template, $layout_template);)
this seems useless : $view_manager->getLayoutFinder()->setName('outer', __DIR__ . '/template/outer.php'); 

I'm gonna look into internal code to get why layout is not rendered. If anyone has any clue, let me know :)

guillaume ferrand

unread,
Feb 11, 2014, 9:33:29 AM2/11/14
to aur...@googlegroups.com
Shame on me... I had a typo in my code which prevented the layout to be found :)

Works good now : view + layout together.

Thanks a lot Hari : super fast and efficient help 
Reply all
Reply to author
Forward
0 new messages