Object Orientation in PHP, crud example with ajax

Asked

Viewed 514 times

1

I’m trying to learn Object-Oriented PHP, but I’m having a hard time finding an example. Someone can show a simple example of the crud case below:

  • A php class, for example user, in this class has methods that return the user by id.

  • return all users.

  • inserts the user.

  • updates the user.

  • deletes the user.

I was also wondering what to call these methods.

In case I will use ajax then I will have to use a php file instantiated the class object.

I apologise for the naiveté, but I believe that here I will have the best examples and support in the doubts.

If anyone knows/has any material relevant to this also thank you.

What I did:

  <?php
    class Listas{
      public $guid;
      public $eguid;
      public $concluida;
      public $titulo;
      public $descricao;
      public $datecreate;

      function listarListas($db){
        $result = $db->select('cad_listaconf');
        $res = array();
        $res = $db->getResult();

        return $res;
      }

      function inserirLista($eguid, $titulo, $descricao, $datecreate, $db){
        if ($query = $db->insert('cad_listaconf', array('eguid'=>$eguid,         'titulo'=>$titulo, 'descricao'=>$descricao, 'datacreate'=>$datecreate))){
          return 1;
        } else {
          return 0;
        }
      }

    }

?>
  • What have you ever tried to do?

  • what I have done so far has created a class, defines the properties and created a method that brings all records using another crud class to that class and I am trying to call this method. my doubt is in the parameter Questa, for example I will create an insertusuario method with its parameters, I do not know how to do

  • Put that part you asked in the question.

  • right, I’ll post what I did, it works but I don’t know if it’s right that way

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.