【问题标题】: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 的新手

【问题讨论】:

    标签: php cassandra namespaces symfony


    【解决方案1】:

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

    你可以找到一个例子here

    【讨论】:

    • 我现在没有使用任何键空间,我只是想在 symfony 中探索 Cassandra,但我不能这样做,因为这个错误消息“尝试从命名空间加载类“时间戳”” Cassandra”。您是否忘记了另一个命名空间的“use”语句?”
    • Timestamp 类只是一种可以存储在 Cassandra 中的数据,而不是一个值本身。如果你想使用 PHP,有一个教程here 可以提供帮助
    猜你喜欢
    • 2015-11-07
    • 2019-10-09
    • 2019-11-18
    • 2020-05-24
    • 1970-01-01
    • 2016-11-07
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多