Error do not require_once

1

I created the file functions.php and included it with function add() , but when I call it on page add.php with the command require_once a fatal error appears.

  

Fatal error: Uncaught Error: Call to undefined function view () in   C: \ xampp \ htdocs \ lester \ customers \ add.php: 3 Stack trace: # 0 {main}   thrown in C: \ xampp \ htdocs \ lester \ customers \ add.php on line 3

Following codes:

This is from the functions.php file

    <?php

    require_once('../config.php');
    require_once(DBAPI);

    $customers = null;
    $customer = null;

    /**
     *  Listagem de Clientes
     */
    function index() {
        global $customers;
        $customers = find_all('customers');
    }

    /**
     *  Cadastro de Clientes
     */

    function add() {

      if (!empty($_POST['customer'])) {

        $today = 
          date_create('now', new DateTimeZone('America/Sao_Paulo'));

        $customer = $_POST['customer'];
        $customer['modified'] = $customer['created'] = $today->format("Y-m-d H:i:s");

        save('customers', $customer);
        header('location: index.php');
      }
    }

    /**      *  Visualização de um Cliente      
     */     

    function view($id = null) {       
        global $customer;         
        $customer = find('customers', $id);     
    }

    ?>

E esse é do arquivo add.php

    <?php 
      require_once('functions.php'); 
      add();
    ?>

    <?php include(HEADER_TEMPLATE); ?>

    <h2>Novo Cliente</h2>

    <form action="add.php" method="post">
      <!-- area de campos do form -->
      <hr />
      <div class="row">
        <div class="form-group col-md-7">
          <label for="name">Nome / Razão Social</label>
          <input type="text" class="form-control" name="customer['name']">
        </div>

        <div class="form-group col-md-3">
          <label for="campo2">CNPJ / CPF</label>
          <input type="text" class="form-control" name="customer['cpf_cnpj']">
        </div>

        <div class="form-group col-md-2">
          <label for="campo3">Data de Nascimento</label>
          <input type="text" class="form-control" name="customer['birthdate']">
        </div>
      </div>


Códigos do arquivo view.php
<?php 
    require_once('functions.php'); 
    view($_GET['id']);
?>

<?php include(HEADER_TEMPLATE); ?>

<h2>Cliente <?php echo $customer['id']; ?></h2>
<hr>

<?php if (!empty($_SESSION['message'])) : ?>
    <div class="alert alert-<?php echo $_SESSION['type']; ?>"><?php echo $_SESSION['message']; ?></div>
<?php endif; ?>

<dl class="dl-horizontal">
    <dt>Nome / Razão Social:</dt>
    <dd><?php echo $customer['name']; ?></dd>

    <dt>CPF / CNPJ:</dt>
    <dd><?php echo $customer['cpf_cnpj']; ?></dd>

    <dt>Data de Nascimento:</dt>
    <dd><?php echo $customer['birthdate']; ?></dd>
</dl>

<dl class="dl-horizontal">
    <dt>Endereço:</dt>
    <dd><?php echo $customer['address']; ?></dd>

    <dt>Bairro:</dt>
    <dd><?php echo $customer['hood']; ?></dd>

    <dt>CEP:</dt>
    <dd><?php echo $customer['zip_code']; ?></dd>

    <dt>Data de Cadastro:</dt>
    <dd><?php echo $customer['created']; ?></dd>
</dl>

Can you tell me why?

    
asked by anonymous 24.10.2017 / 03:31

0 answers