PHP code example of bombkiml / phpbeech

1. Go to this page and download the library: Download bombkiml/phpbeech library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bombkiml / phpbeech example snippets


    

    class FruitsController extends Controller {
    
        /**
         * @Rule: consturctor class it's call __construct of parent class
         *
         * Call parent class
         *
         */
        public function __construct() {
        
            parent::__construct();
            
        }
    }

    

    class FruitsController extends Controller {
    
        /**
         * @Rule: consturctor class it's call __construct of parent class
         *
         * Call parent class
         *
         */
        public function __construct() {
        
            parent::__construct();
            
        }
        
        /**
         * Simple passing the data to `views/fruits/fruits.view.php`
         * 
         * @var title
         * @var hello
         * @var data
         *
         * @return Response view
         */
        public function index() {
        
            // Passing the data to view
            $this->view->title = "fruits page";
            $this->view->sayHello = "Hello fruits";
            $this->view->data  = [];
            
            // Return response view
            return $this->view->render("fruits/fruits.view");
            
        }
        
    }

     

    class Fruits extends Model {
        
        /**
         * @Rule: consturctor class it's call __construct of parent class
         *
         * Call parent class
         *
         */
        public function __construct() {
        
            parent::__construct();
            
        }

        /**
         * Simple method using MySQL get data
         *
         */
         public function getFruits() {
            
            // Preparing sql statements
            $stmt = $this->db->prepare("SELECT * FROM fruits");
            
            // Execute statements
            $stmt->execute();
            
            // Return response rows
            return $stmt->fetch_all();
            
         }
    }
 $this->db 

    $stmt = $this->db->prepare("SELECT * FROM fruits");

    $stmt->execute();

    $stmt->fetch_all();
    // result: array
    
    $stmt->fetch_assoc();
    // result: array
    
    $stmt->fetch_array();
    // result: array
    
    $stmt->fetch_object();
    // result: object
    
    $stmt->num_rows();
    // result: int


    // Init autocommit off
    $this->db->transaction();
    
    // update, delete some value
    $this->db->update("fruits", array("name" => "Cherry"), array("id" => 1));
    $this->db->delete("fruits", array("id" => 1));
    
    // commit transaction
    if ($this->db->commit()) {    
        
        echo "Commit completed!";    
        
    } else {
    
        // Rollback transaction
        $this->db->rollback();        
        
    }

    

    class FruitsController extends Controller {
    
        public function __construct() {        
            parent::__construct();
        }
        
        /**
         * Simple calling the model `Fruits`
         * 
         */
        public function index() {
        
            // Calling the method in model
            $this->view->fruits = $this->model->getFruits(); // <---- Call method in Fruits model
                        
            // Return response view
            return $this->view->render("fruits/fruits.view");
            
        }
        
    }

    $this->db->insert("fruits", array("id" => "1", "name" => "Banana"));

    $this->db->update("fruits", array("name" => "Cherry"), array("id" => 1));

    $this->db->delete("fruits", array("id" => 1));
 modules/controllers/fruits/fruitsController.php 
 views/fruits/fruits.view.php 
html
    <html>
        <head>
    
            <!-- Accessing the data passed of @var title -->
            <title> echo $this->title; 
 $this->db 
$this->model