Reputation: 151
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?
Upvotes: 2
Views: 3051
Reputation: 164936
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
Upvotes: 6