PHP code example of elementphp / element

1. Go to this page and download the library: Download elementphp/element 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/ */

    

elementphp / element example snippets


"domain" =>[
	"host" => "localhost/",
	"root" => "element"
],

 

namespace element\mvc;

class Example extends Model {
    public $id;
    public $message;
}



 

namespace element\mvc;

class IndexController extends Controller {
    
    public function indexAction() {
        
        /*
           If id is AI primary key we shouldn't explicitly set it.
        */
        
        // create and save model
        $model = new Example();
        $model->message = "Hi there!";
        $model->save(true);
        
        // retrieve model
        // kind of redundant, because we have it in $model, just to explain! :)
        $example = Example::getById($model->id);

        // pass our message to view
        $this->view->assign('message', $example->message);
    }
}