1
Hello to everyone I’m having trouble to concatenate a session in php, what I intended would be the following a page to insert into an object, and then the values I would concatenate. my product class I made so.
class Produto {
protected $nome;
protected $valor;
public function __construct($nome, $valor) {
$this->nome = $nome;
$this->valor = $valor;
}
public function addProd($nome, $valor){
$prod = new Produto($nome, $valor);
}
public function getNome() {
return $this->nome;
}
public function setNome($nome) {
$this->nome = $nome;
}
public function getValor() {
return $this->valor;
}
public function setValor($valor) {
$this->valor = $valor;
}
function __toString() {
$this->nome + $this->valor;
}
then I made the page that displays the values, in case my index.
<?php
session_start();
if(isset($_GET["acao"]) and $_GET["acao"] == "ok") {
$_SESSION["nome"] = $_POST["nome"];
$_SESSION["valor"]= $_POST["valor"];
$prod = new Produto($_SESSION["nome"], $_SESSION["valor"]);
//gostaria de conseguir concatenar aqui esses valores
echo $prod->getNome() . $prod->getValor();
}
?>
and my page to enter the values in the session.
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<div class="container">
<div class="row-fluid">
<div class="span4">
</div>
<div class="span4">
<div class="well">
<form action="index.php?acao=ok" method="post">
<fieldset>
<center><legend>Adicione um produto e seu valor</legend> </center>
<label>Descrição do produto</label>
<input class="input-xlarge" type="text" placeholder="Digite o nome do produto" name="nome" autofocus required>
<label>Valor do produto</label>
<input class="input-xlarge" type="number" placeholder="R$" name="valor" required>
</br></br>
<button type="submit" class="btn btn-primary">Salvar</button>
</fieldset>
</form>
</div>
</div>
<div class="span4">
</div>
</div>
I’ve tried a few ways to concatenate, but I’m a bit of a beginner in php and I’m not getting it, I summarized the code to make it easier to read.
André, it was not clear in your code where the session part comes in. I could explain better?
– gmsantos