PHP code example of slaxweb / ci-basemodel

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

    

slaxweb / ci-basemodel example snippets


class Some_model extends \SlaxWeb\BaseModel\Model


use \SlaxWeb\BaseModel\Constants as C;

class Test_model extends \SlaxWeb\BaseModel\model
{

}

$this->insert(array("column" => "value"));

// retrieves row with primary key value 123
$this->get(123);

$this->getBy(array("column" => "value"));

$this->update(array("column" => "value"), 123);

$this->updateBy(array("column" => "value"), array("whereColumn" => "whereValue"));

$this->join(
  "table2",
  array(
    array(
      "leftTable"   =>  "customTable",
      "leftColumn"  =>  "leftCol1",
      "rightTable"  =>  "rightCustomTable",
      "rightColumn" =>  "rightCol1",
    ),
    array(
      "leftColumn"      =>  "leftCol2",
      "rightColumn"     =>  "rightCol2",
      "logicalOperator" =>  "OR"
    )
  )
);

$this->join("table2", array(array("column1", "column1"), array("column2", "column2", "OR")));

$this->wBuild->add("columnName", "value");

$this->where("columnName1", "value")->get();

$this->wBuild->add("columnName1", "value1")->add("columnName2", 10);

$this->wBuild->add("columnName", array("value1", "value2"), "",  "IN");

$this->wBuild->add("columnName", $this->get(123), "", "NOT IN");

$this->where(array("columnName1 = ?", array("value1")))->get();

$this->wBuild->add("columnName", "value", "", "", "tableName");

$this->getBy(array("column1" => "value1", "OR column2" => "value2"));

$this->getBy(array("column1 <" => 10));

$this->getBy(
 array(
  array(
   "groupCol1" => "groupVal1",
   "groupCol2" => "groupVal2"
  ),
  "OR column1" => "value1"
 )
);

$this->orderBy(
  array(
    "col1" => "ASC",
    "col2  => "DESC"
  )
);

$this->rules = array(
    array(
        "field" =>  "fieldName",
        "label" =>  "Field label",
        "rules" =>  "

$this->rules = array(
    array(
        "field" =>  "fieldName",
        "label" =>  "Field label",
        "rules" =>  "

$this->skipValidation()->insert($data);

$this->withDeleted()->get();

$result = $this->getBy(array("whereColumn" => "whereValue"), "column");
$result->column;

$result->asArray();

$error->hasErrors();
$error->errorCount();