Software:Sansa Framework: Difference between revisions

From HandWiki
(over-write)
 
(import)
Line 1: Line 1:
{{Proposed deletion/dated
  |concern = WP:NOTHOWTO.
  |timestamp = 20240620144953
  |nom = Let'srun
  |help = off
}}
{{Multiple issues|
}}
'''Sansa Framework''' is a structure to create [[Organization:PHP|PHP]] web applications using the [[Model–view–controller|model–view–controller]] (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 database.
'''Sansa Framework''' is a structure to create [[Organization:PHP|PHP]] web applications using the [[Model–view–controller|model–view–controller]] (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 database.


To insert a new record to the table, create a new instance of a class, fill the properties and call the insert method.  
To insert a new record to the table, create a new instance of a class, fill the properties and call the insert method.  
<source lang="php">
<syntaxhighlight lang="php">
$usr = new users();
$usr = new users();
$usr->name = "test";
$usr->name = "test";
$usr->insert();
$usr->insert();
</source>
</syntaxhighlight>
The code above insert one record to the table '''users''' with the name '''test'''.
The code above insert one record to the table '''users''' with the name '''test'''.
<source lang="php">
<syntaxhighlight lang="php">
$usr = new users();
$usr = new users();
if ($usr->get("name")->where("id=1")->exe()) {
if ($usr->get("name")->where("id=1")->exe()) {
Line 17: Line 26:
     }
     }
}
}
</source>
</syntaxhighlight>
The code above print '''test.'''
The code above print '''test.'''
<source lang="php">
<syntaxhighlight lang="php">
$usr = new users(1);
$usr = new users(1);
echo $usr->name;
echo $usr->name;
</source>
</syntaxhighlight>
The code above print '''test''' too.
The code above print '''test''' too.


'''Complex code:'''
'''Complex code:'''


<source lang="php">
<syntaxhighlight lang="php">
public function save($arr)
public function save($arr)
{
{
Line 44: Line 53:
     return $result;
     return $result;
}
}
</source>
</syntaxhighlight>


The code below shows how to create joins.
The code below shows how to create joins.


<source lang="php">
<syntaxhighlight lang="php">
require($_SERVER['DOCUMENT_ROOT'] . '/layers/bll/users.php');
require($_SERVER['DOCUMENT_ROOT'] . '/layers/bll/users.php');
require($_SERVER['DOCUMENT_ROOT'] . '/layers/bll/rights.php');
require($_SERVER['DOCUMENT_ROOT'] . '/layers/bll/rights.php');
Line 64: Line 73:
     }
     }
}
}
</source>
</syntaxhighlight>


==External links==
==External links==

Revision as of 16:24, 21 June 2024

Sansa Framework is a structure to create PHP web applications using the model–view–controller (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 database.

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>";
    }
}

External links