Junnama Noda, president of Alfasado Inc., wrote an entry about a MT5’s New php API.
In this entry, he wrote some sample codes to use MT’s new API for php.
I think it is very useful for MT' developers, so I try to translate and introduce them.
Please let me know if there are the wrong points in my English usage.
*Loading an entry data
$args['class'] = 'entry'; $args['blog_id'] = $blog_id; $args['offset']=n; $args['limit']=n; $entries = $ctx->mt->db()->fetch_entries($args);
*Loading an entry or other object data via sql, with range specification
$entries = $ctx->mt->db()->SelectLimit( $sql, $limit, $offset );
*Executing sql
$entries = $ctx->mt->db()->Execute( $sql );
*Getting a number of object data
$entries->RecordCount();
*Loading each records
$entries->Move($counter); $entry = $entries->FetchRow();
*Definiting an entry data as an object
(attention: you need to coordinate definition of category, custom fields, and other MT’s data in the sql settings)
$e; while(list ($key, $val) = each($entry)) { if (preg_match('/^entry_/',$key)) { $e->$key = $val; } } # $ctx->stash('entry', $e);
*Loading an object from an arbitrary entry data
$e = $ctx->mt->db()->fetch_entry($id)
*Loading an object from a web page data
$e = $ctx->mt->db()->fetch_page($id);
*Loading an object with “Find” method
require_once 'class.mt_entry.php'; #entry $_entry = new Entry; $where = $where_statment; $extra = array( 'limit' => $limit, 'offset' => $offset, ); $results = $_entry->Find($where, false, false, $extra);

Leave a comment