尝试从命名空间加载类您是不是忘记了另一个命名空间的“使用”语句?

Posted

技术标签:

【中文标题】尝试从命名空间加载类您是不是忘记了另一个命名空间的“使用”语句?【英文标题】:Attempted to load class from namespace did you forget a "use" statement for another namespace?尝试从命名空间加载类您是否忘记了另一个命名空间的“使用”语句? 【发布时间】:2017-02-12 01:31:56 【问题描述】:

我在我的代码中使用了 Cassandra 类,并且此错误始终显示“尝试从命名空间加载类,您是否忘记了另一个命名空间的“使用”语句?”这是我的代码

默认控制器

<?php

namespace Acme\SampleBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Cassandra;

class DefaultController extends Controller

public function indexAction()

    $con = new Cassandra\Timestamp();

    echo $con;


时间戳.php

<?php

/**
* Copyright 2015-2016 DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Cassandra;

/**
* A PHP representation of the CQL `timestamp` datatype
*/
final class Timestamp implements Value

/**
 * Creates a new timestamp from either unix timestamp and microseconds or
 * from the current time by default.
 *
 * @param int $time Unix timestamp
 * @param int $usec Microseconds
 */
public function __construct($time = null, $usec = null) 

/**
 * The type of this timestamp.
 *
 * @return Type
 */
public function type() 

/**
 * Unix timestamp.
 *
 * @return int seconds
 * @see time
 */
public function time() 

/**
 * Microtime from this timestamp
 *
 * @param bool $get_as_float Whether to get this value as float
 *
 * @return float|string Float or string representation
 * @see microtime
 */
public function microtime($get_as_float = false) 

/**
 * Converts current timestamp to PHP DateTime.
 *
 * @return \DateTime PHP representation
 */
public function toDateTime() 

/**
 * Returns a string representation of this timestamp.
 *
 * @return string timestamp
 */
public function __toString() 

我不知道我的代码有什么问题,我是使用 Cassandra 和 symfony 的新手

【问题讨论】:

【参考方案1】:

你是在配置文件中定义keyspace吗?

你可以找到一个例子here

【讨论】:

我现在没有使用任何键空间,我只是想在 symfony 中探索 Cassandra,但我不能这样做,因为这个错误消息“尝试从命名空间加载类“时间戳”” Cassandra”。您是否忘记了另一个命名空间的“use”语句?” Timestamp 类只是一种可以存储在 Cassandra 中的数据,而不是一个值本身。如果你想使用 PHP,有一个教程here 可以提供帮助

以上是关于尝试从命名空间加载类您是不是忘记了另一个命名空间的“使用”语句?的主要内容,如果未能解决你的问题,请参考以下文章

尝试从命名空间“App\DataFixtures”加载类“BaseFixture”。您是不是忘记了另一个名称空间的“使用”语句?

创建一个新项目和捆绑包 - “您是不是忘记了另一个命名空间的 'use' 语句?”

在另一个命名空间中自动加载命名空间时出错

在Composer更新后找不到Symfony AbstractController

尝试从命名空间“Application\MediaBundle\Entity”加载类“Media”

Symfony 5.1.3 清除缓存时的问题:尝试从命名空间加载类“MappingDriverChain”