zf2 request object

For programming and general questions on Zend Framework

zf2 request object

Postby tporter on Thu Nov 29, 2012 11:44 pm

Hey all,

I'm not sure if this is a zf or studio 10 question really, so figured i'd start here as i think its more code related.

I'm working on a new project trying to figure out the changes from zf1 to zf2, I have a few questions.

In zf1 if i wanted to dump something as debug to the browser i'd do this

Code: Select all
Zend_Debug::Dump('this is the output");


Now, in zf2 I think i do this

Code: Select all
use Zend\Debug\Debug;
Debug::dump("this is the output") ;


Ok, not sure why the double Debug but thats what the code completion puts in the file...

So i want a param from the request object :

In zf1,

Code: Select all
$singleParam = $this->getRequest()->getParam("testVar");
$allParams = $this->getRequest()->_getParams();


Now in zf2,

Code: Select all
use Zend\Http\PhpEnvironment\Request;
$singleParam = $this->getRequest()->getParam('testVar')
$allParams = ????


Is there a getParams or getAllParams?

I couldn't find the getParams or a getAllParams in zf2, this is where i'm unsure as to if this is a code thing or a studio 10 beta thing. The syntax code complete in studio doesn't see the getParam function, it only has four choices (getContent, getMetadata, setContent & setMetadata).

Anyone know why the code complete doesn't see these functions? ...maybe i'm using the wrong Request namespace?...

Is it normal to not have code completion with the namespace style programming? I haven't use namespace codeing, its all be classes.

Please toss me some crumbs
tporter
 
Posts: 39
Joined: Thu Mar 05, 2009 5:35 pm

Re: zf2 request object

Postby tporter on Sat Dec 01, 2012 4:03 am

This looks to be some weird thing going on in zend studio 10 beta ...
tporter
 
Posts: 39
Joined: Thu Mar 05, 2009 5:35 pm

Re: zf2 request object

Postby bondvt04 on Sat Dec 01, 2012 6:22 pm

Maybe, completion is not always possible. For example:
Code: Select all
class A
{
    protected $myMethods = array();//
   
    function __construct()
    {
        $this->myMethods = array(
            'foo' => function() {
                return 'bar';
            },
            'baz' => function() {
                return 'bat';
            }
        );
    }
   
    function hello()
    {
        return 'hello';
    }
   
    function __call($name, $params = array())
    {
        return $this->myMethods[$name]($params);
    }
}

\Zend\Debug\Debug::dump((new A)->foo());exit();

How in this case *your favorit editor* will quess about methods foo() and baz()? :)
For most cases, usable Reflection Api, example:
Code: Select all
\Zend\Debug\Debug::dump((new \ReflectionClass($this->getRequest()))->getMethods());exit();
bondvt04
 
Posts: 3
Joined: Sat Dec 01, 2012 5:55 pm


Return to Zend Framework

Who is online

Users browsing this forum: Google [Bot] and 8 guests