Ejemplo n.º 1
0
function rest_search($text)
{
    $post_info = array();
    // normally this info would be pulled from a database.
    // build JSON array.
    $posts = PostModel::where('title', 'like', "%{$text}%")->get();
    if (count($posts) > 0) {
        foreach ($posts as $p) {
            array_push($post_info, array("id" => $p['id'], "title" => $p['title'], "user_id" => $p['user_id'], "filename" => $p['upload_filename'], "date" => $p['upload_date'], "img_path" => $p['thumb_img_path']));
        }
        $image_list = array('post_info' => $post_info, 'ret_val' => "success");
    } else {
        // echo 'fail to get user info';
        $image_list = array('ret_val' => "fail", 'ret_detail' => "fail to get my post info");
    }
    // 	$mysqli = new mysqli ( "localhost", "root", "111111", 'db_chat_member_test' );
    // 	if ($mysqli->connect_errno) {
    // 		echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    // 	}
    // 	$sql_query = "SELECT id, user_id, title, upload_filename, db_filename, filepath, upload_date, category, thumb_img_path
    // 	                   FROM posts WHERE title LIKE '%$text%'";
    // 	if ($result = $mysqli->query ( $sql_query )) {
    // 		if (count ( $result ) > 0) {
    // 			$post_info = array ();
    // 			while ( $row = $result->fetch_assoc () ) {
    // 				array_push ( $post_info, array (
    // 						"id" => $row ['id'],
    // 						"title" => $row ['title'],
    // 						"user_id" => $row ['user_id'],
    // 						"filename" => $row ['upload_filename'],
    // 						"date" => $row ['upload_date'],
    // 						"img_path" => $row ['thumb_img_path']
    // 				) );
    // 			}
    // 			$image_list = array (
    // 					'post_info' => $post_info,
    // 					'ret_val' => "success"
    // 			);
    // 		} else {
    // 			// echo 'fail to get user info';
    // 			$image_list = array (
    // 					'ret_val' => "fail",
    // 					'ret_detail' => "fail to get my post info"
    // 			);
    // 		}
    // 	} else {
    // 		$image_list = array (
    // 				'ret_val' => "fail",
    // 				'ret_detail' => "no post data in db"
    // 		);
    // 	}
    // 	$mysqli->close ();
    return $image_list;
}
Ejemplo n.º 2
0
$post->add_comment("testing", "*****@*****.**", "cool post");
$post->save();
for ($i = 0; $i < 1000; $i++) {
    /* Add another post */
    $post->reset();
    /* reet the post object */
    $post->uri = "/" . uniqid();
    $post->title = "Yet another post ({$i})";
    $post->author = $author->getID();
    $post->save();
}
/* Clean up the current the resultset */
/* same as $post = null; $post = new Post Model */
/* but more efficient */
$post->reset();
$post->where('author', $author->getID());
foreach ($post as $bp) {
    var_dump("Author: " . $bp->author_name);
}
$author->name = "cesar d. rodas";
$author->save();
var_dump("Author profile has been updated");
/** 
 *  List our blog posts in the correct order
 *  (descending by Timestamp).
 */
$post->reset();
$post->columns("title, uri, author_name, author_username, ts");
$post->sort("ts DESC");
$post->limit(PostModel::LIMIT_PER_PAGE);
foreach ($post as $bp) {