1

im cofusing how to create a new instance of an object in ZF2. My class is called Clientela and i want to create a new instance of this class in another page, but im getting an error trying to do this.

My class is:

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


?>

and im trying to initialize in another page .php

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

$cli = new Cli();

But its not working. Error:

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

How can i do that?

4
  • Are you trying to create a instance of Cli inside your view? Commented Jan 19, 2018 at 17:33
  • Yes, just for understand. Commented Jan 19, 2018 at 17:36
  • 2
    Try use Magento\Framework\Model\ResourceModel\Clientela\Clientela as Cli;. The way you create an object instance in ZF is no different to PHP. Commented Jan 19, 2018 at 17:41
  • Do i have to map this class? Its still not working. Commented Jan 19, 2018 at 18:06

1 Answer 1

1

It works after i set a "\" after all:

Page A:

 $cliente = new \Magento\Framework\Model\ResourceModel\Clientela\Clientela(1,"raulzito","[email protected]");

Class:

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

}

?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.