Sansa Framework

Sansa Framework is a structure to create PHP web applications using the MVC model, it's a web application that must be installed in a server to work, could be installed in a test server or in production server. The developer must create a data model and do all the changes the project need and at any time generate the model. The generation CREATES a Database in Mysql server with the same name of the model and a n-tier layer of libraries to handle the Db.

To insert a new record to the table, create a new instance of a class, fill the properties and call the insert method.

$usr = new users();
$usr->name = "test";
$usr->insert();

The code above insert one record to the table users with the name test.

$usr = new users();
if($usr->get("name")->where("id=1")->exe()){
  if($usr->count>0){
    foreach($usr->dobj as $d){
      echo $d->name."<br>";
    }
  }
}

The code above print test.

$usr = new users(1);
echo $usr->name;

The code above print test too.

Complex code:

public function save($arr){
 $result = false;
 $this->arr_to_prop($arr); //this method clear the array of risky code and 
 //assign $this->name = $arr['mappname'] and any other property.
 $index=$arr['index'];
 if($index==0){                //new
   $result = $this->insert();
 }else{                        //edit
   if(isset($_SESSION['dusers'])){
     $id=$_SESSION['dusers'][$index]['id']
     $result = $this->update($id);
   }
 }
 return $result;
}

The code below shows how to create joins.

require($_SERVER['DOCUMENT_ROOT'] . '/layers/bll/users.php');
require($_SERVER['DOCUMENT_ROOT'] . '/layers/bll/rights.php');
require($_SERVER['DOCUMENT_ROOT'] . '/layers/bll/access.php');

$u = new users();

if($u->join($r = new rights())->on(array($u->rightid(), EQUAL, $r->id()))
     ->join($a = new access())->on(array($r->idaccess(), EQUAL, $a->aid()))
     ->get(array($u->name(), $r->rname(), $a->aname()))
     ->exe()){
  //echo $u->sqlstr."<br><br>"; //print the resulting sql if you need it.
  foreach($u->dobj as $d){
    echo $d->name." ".$d->rname." ".$d->aname."<br>";
  }
}