调用方法(Calling Methods)

As seen when calling functions, in Phalcon the methods are called in the PHP userland. Thanks to this, a Phalconuser can generate a backtrace and know exactly which components are involved in a given task. They alsoallows users to replace Phalcon components by PHP classes of their own. Additionally,like everything else we’ve seen, the way to make calls is familiar to PHP developers.

调用实例方法(Instance methods)

  1. // Define the connection DSN
  2. ZVAL_STRING(&dsn, "mysql:host=localhost;username=root;password=secret;dbname=some");
  3.  
  4. // Get the PDO class entry
  5. pdo_class_entry = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO);
  6.  
  7. // Create a PDO instance passing the dsn to the constructor
  8. object_init_ex(&pdo, pdo_class_entry);
  9. PHALCON_CALL_METHOD(NULL, pdo, "__construct", &dsn);
  10.  
  11. // Create a SQL statement
  12. ZVAL_STRING(&sql_statement, "SELECT * FROM robots");
  13.  
  14. // Call the "exec" method in the pdo object passing the sql_statement
  15. PHALCON_CALL_METHOD(&success, &pdo, "exec", &sql_statement);

调用静态方法(Static methods)

  1. ZVAL_STRING(&some_variable, "invoices_detail");
  2.  
  3. // Calling Phalcon\Text::camelize("invoices_detail")
  4. PHALCON_CALL_STATIC(camelized, "phalcon\\text::camelize", some_variable);