RISE to Bloome Software
Log In    
Home
RISE
Marshal
Download
 
 
r2bsoftware.se r2bsoftware.se
 
 
 
Click to hide navigation tree
PHP custom method
The sample code in this article is available for download.
 
A PHP custom method implementation needs to meet the following requirements:
  1. The implementation file must be named according to namespace specified in the RISE Editor, i.e. <namespace>.php.
  2. The implementation file must contain (implement) the class assigned to the RISE custom method.
  3. 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.
  4. 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.