在Zend Framework 2中创建对象的新实例

时间:2018-01-19 17:31:44

标签: php zend-framework zend-framework2 magento2

我如何在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

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我设置了一个&#34; \&#34;毕竟:

第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;
}

}

?>