2

Trying to have a look on zend2 I'm working on the zend skeleton.

On the Controller, I'm adding the following code:

// Decode JSON objects as PHP objects
$data = $request->getPost('album');
$result = Zend\Json\Json::decode($data);   // line 82

And I get the following error:

Fatal error: Class 'Album\Controller\Zend\Json\Json' not found in C:\wamp\www\zf2-skeleton\module\Album\src\Album\Controller\AlbumController.php on line 82

Having a look on the official documentation, but I don't find anything that help me.

Maybe can you help me to understand what is missing?

1 Answer 1

6

You are using a qualified (relative) name so PHP assumes Zend\Json\Json is within your namespace (ie \Album\Controller).

You need to prefix the entire inline name with a backslash to create a fully qualified name, eg

$result = \Zend\Json\Json::decode($data);

Otherwise, you can add the appropriate use statement at the top of your file (under the namespace section)...

use Zend\Json\Json;

and simply use the class name in your code...

$result = Json::decode($data);

See http://php.net/manual/language.namespaces.basics.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.