【问题标题】:Create new Instance of an Object in Zend Framework 2在 Zend Framework 2 中创建对象的新实例
【发布时间】:2018-01-19 17:31:44
【问题描述】:

我很困惑如何在 ZF2 中创建对象的新实例。 我的课程名为 Clientela,我想在另一个页面中创建此类的新实例,但尝试执行此操作时出错。

我的班级是:

<?php 

namespace Magento\Framework\Model\ResourceModel\Clientela;

use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\ResourceModel\AbstractResource;

class Clientela{

private $id;
private $nome;
private $email;

public function __construct(){
}

public function getId(){
    return $this->id;
}

public function setId($id){
    $this->id = $id;
}

public function getNome(){
    return $this->nome;
}

public function setNome($nome){
    $this->nome = $nome;
}

public function getEmail(){
    return $this->email;
}

public function setEmail($email){
    $this->email = $email;
}
}


?>

我正在尝试在另一个页面中初始化 .php

use Magento\Framework\Model\ResourceModel\Clientela as Cli;

$cli = new Cli();

但它不起作用。 错误:

Fatal error: Class 'Magento\Framework\Model\ResourceModel\Clientela' not found in /var/www/html/vendor/magento/module-contact/view/frontend/templates/form.phtml on line 20

我该怎么做?

【问题讨论】:

  • 您是否尝试在您的视图中创建Cli 的实例?
  • 是的,只是为了理解。
  • 试试use Magento\Framework\Model\ResourceModel\Clientela\Clientela as Cli;。在 ZF 中创建对象实例的方式与 PHP 没有什么不同。
  • 我必须映射这个类吗?它仍然无法正常工作。

标签: php zend-framework zend-framework2 magento2


【解决方案1】:

毕竟在我设置了“\”之后它就可以工作了:

A页:

 $cliente = new \Magento\Framework\Model\ResourceModel\Clientela\Clientela(1,"raulzito","soares@example.com");

类:

<?php

namespace Magento\Framework\Model\ResourceModel\Clientela;

use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\ResourceModel\AbstractResource;

class Clientela {

private $id;
private $nome;
private $email;

public function __construct($id,$nome,$email){
    $this->id = $id;
    $this->nome = $nome;
    $this->email = $email;
}

public function getId(){
    return $this->id;
}

public function setId($id){
    $this->id = $id;
}

public function getNome(){
    return $this->nome;
}

public function setNome($nome){
    $this->nome = $nome;
}

public function getEmail(){
    return $this->email;
}

public function setEmail($email){
    $this->email = $email;
}

}

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    相关资源
    最近更新 更多