Shadow Export [RFC]

116 views
Skip to first unread message

Andres Gutierrez

unread,
Jan 10, 2013, 3:30:04 PM1/10/13
to pha...@googlegroups.com
This RFC is to discuss the implementation of "shadow export of local scopes to views" (sorry, suggest a better name).

Introduction

Currently to pass values from controller to the view you need to use $this->view->setVar('post', $post),

With the implementation of this NFR, Phalcon automatically could export the variables in the local scope of the last executed method (normally the action method) to the views:

<?php

class PostsController extends Phalcon\Mvc\Controller
{

    public function editAction($id)
    {
        $post = Post::findFirst(array(
            'id = ?0',
            'bind' => array($id)
        ));
    }
   
}

Then in the view:

<h1><?php echo $post->title ?></h1>

The $post and $id variables are automatically exported to the views.

Advantages: Less coding
Disadvantages: This way to pass variables to the view can not be natural at all, leading to errors if this behavior is unknown/unclear to the developer.

Please vote with +1 or -1 if you want/don't want that this being implemented in a next release. Please add comments on possible drawbacks or disadvantages of adding this.

Nikolaos Dimopoulos

unread,
Jan 10, 2013, 7:28:14 PM1/10/13
to pha...@googlegroups.com
+0.5

Although I like the idea of less coding, we are entering a danger area where the framework does all the work for the developer thus allowing laziness and potential bugs.

Automatically injecting variables from the last action to the view could effectively save a lot of time (as you showed in your example). For sure that helps with coding.

However if you extend your controller from a base one and the base controller sets some variables (which will end up in the view with this feature), and then in turn set the same variables in your actual action, you will end up trying to find where the bug is and why your data is not displayed.

I can see the value of it but I am not that keen on the idea (hence the 0.5)

I would have preferred a magic method for the view like so:

$this->view->post = $post

vs.

$this->view->setVar('post', $post);

HTH

The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.



--
You received this message because you are subscribed to the Google Groups "Phalcon PHP Framework" group.
To post to this group, send email to pha...@googlegroups.com.
To unsubscribe from this group, send email to phalcon+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Antonio Lopez

unread,
Jan 10, 2013, 7:57:27 PM1/10/13
to pha...@googlegroups.com
what kind of sorcery is this? I like the intention but -1

On Thu, Jan 10, 2013 at 3:30 PM, Andres Gutierrez <andres.g...@phalconphp.com> wrote:

--

dschissler

unread,
Jan 10, 2013, 8:01:53 PM1/10/13
to pha...@googlegroups.com, andres.g...@phalconphp.com
-1 scares the hell out of me.  I'll hope to god that when I make up this is not accepted.

Romanko

unread,
Jan 10, 2013, 8:21:23 PM1/10/13
to pha...@googlegroups.com, andres.g...@phalconphp.com
Hey Andres,

I think in Phalcon 2.x you introduce something which will write the code itself making developers work redundant :) 

-1 to this one and I explain you why:
  1. Local scope must be cleaned off any variables you don't want to get to views
  2. Where is already a way of doing this in PHP:
$view->setVars( compact('post', 'id') );

... as per your example below :)

Николай Измайлов

unread,
Jan 11, 2013, 12:23:31 AM1/11/13
to pha...@googlegroups.com
Know it's better

$this->render('view', array('test'=>123));


2013/1/11 Romanko <roman....@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Phalcon PHP Framework" group.
To post to this group, send email to pha...@googlegroups.com.
To unsubscribe from this group, send email to phalcon+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/phalcon/-/txcTtJAMaogJ.

Andres Gutierrez

unread,
Jan 11, 2013, 2:06:53 PM1/11/13
to pha...@googlegroups.com
Thank you for your comments here, I think this will eventually not be implemented :)

2013/1/10 Andres Gutierrez <andres.g...@phalconphp.com>

dschissler

unread,
Jan 12, 2013, 11:44:10 AM1/12/13
to pha...@googlegroups.com, andres.g...@phalconphp.com
Thanks Andres but I already lost two days of sleep now. :)

Andres Gutierrez

unread,
Jan 12, 2013, 3:00:39 PM1/12/13
to pha...@googlegroups.com
:D

2013/1/12 dschissler <david.s...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Phalcon PHP Framework" group.
To post to this group, send email to pha...@googlegroups.com.
To unsubscribe from this group, send email to phalcon+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/phalcon/-/swCUTHuPi7kJ.

aavolkoff

unread,
Jan 13, 2013, 11:07:45 PM1/13/13
to pha...@googlegroups.com, andres.g...@phalconphp.com
-1.

I thhink that
```
$this->view->setVar('post', array(...))
```
is the best solution.

пятница, 11 января 2013 г., 0:30:04 UTC+4 пользователь Andres Gutierrez написал:
Reply all
Reply to author
Forward
0 new messages