Log In
Marshal
Overview
How to model
Modeling resources
How to run
Software
RISE
Overview
Getting Started
Information Modeling
View Modeling
Interface Modeling
Code Generators
MySQL
PostgreSQL
SQL Server
C# (.NET)
PHP for MySQL
PHP for PostgreSQL
AJAX
Visual Studio Development
AJAX Development
Test Your Server
Download
Marshal Software
Marshal Editor
Marshal SQL Utility - FREE
Marshal Archiver
Marshal Integrator
Marshal Repository
RISE Software
RISE Editor - FREE
Visual Studio Extension
Code Generators - FREE
Company
About Us
Home
RISE
RISE
Overview
Product feature list
RISE Visual Modeling
How to get started
Information Modeling
Interface Modeling
Basic methods
Composed methods
Custom methods
c# custom method
PHP custom method
Handling BLOBs
Listing by relation
Extended queries
User managed methods
Private interfaces
Connection strings
Server security
Code generators
Application Development
Customization
Philosophy of RISE
User Community
Marshal
Download
r2bsoftware.se
PHP custom method
The sample code in this article is available for
download
.
A PHP custom method implementation needs to meet the following requirements:
The implementation file must be named according to namespace specified in the RISE Editor, i.e.
<namespace>.php
.
The implementation file must contain (implement) the class assigned to the RISE custom method.
The implementation class must provide a constructor. The constructor might have zero arguments, if no database is used in the code or accept a database connection, see samples below.
The implementation class must implement the custom methods, having the same signature (name, arguments and output) as the corrresponding RISE custom methods.
Suppose we create an interface, MyInterface, in a RISE model having prefix MyPrefix. MyInterface is then assigned a method, MyMethod, with a signature according to the picture below.
We also specify, in the RISE Editor, that the method should use the class MyClass in the namespace MyNamespace. Once this is done we generate the interface. The generated code will include (require_once) the file MyNamespace.php and call the method MyMethod. An implementation of this file could look like:
<?php
class MyClass{
public function __construct() {
}
public function MyMethod($a) {
return (object)array("b"=>"MyMethod got " . $a );
}
}
If your model contains an information model (database) that you're interested in accessing from the custom code, the custom code would instead look like:
<?php
class MyClass{
public $conn;
public function __construct($conn) {
$this->conn = $conn;
}
public function MyMethod($a) {
// Do something with $conn
return (object)array("b"=>"MyMethod got " . $a );
}
}
The passed in database connection object,
$conn
above, depends on the database interface used, such as MySQLi. See
PHP database extensions
for further assistance on how to use the connection object.