/** * Index action * Show all blog posts */ public function index() { $blog = new Blog(); $params = array('blogs' => $blog->findAll()); $this->setParams('params', $params); $this->render(); }
public function index() { // Blogクラスから$Blogインスタンス生成 $Blog = new Blog($this->plural_resource); $sql = $Blog->findAll(); // 'SELECT * FROM blogs'という文字列が返ってくる $blogs = mysqli_query($this->db, $sql) or die(mysqli_error($this->db)); return $blogs; }
public function index($category_id) { //var_dump($_GET['search']); // Blogクラスから$Blogインスタンス生成 $Blog = new Blog($this->plural_resource); if (isset($_GET['search'])) { $sql = $Blog->findAll($category_id, $_GET['search']); } else { $sql = $Blog->findAll($category_id); // 'SELECT * FROM blogs'という文字列が返ってくる } //var_dump($sql); $blogs = mysqli_query($this->db, $sql) or die(mysqli_error($this->db)); //var_dump($blogs); //var_dump('test'); $Category = new Category('categories'); $cat_sql = $Category->findAll(); //var_dump($cat_sql); $categories = mysqli_query($this->db, $cat_sql) or die(mysqli_error($this->db)); //var_dump($categories); $return['blogs'] = $blogs; $return['categories'] = $categories; return $return; }
public function actionView($id) { $id = intval($id); $blog = Blog::model()->find('id=:id', array('id' => $id)); $blog->views += 1; $blog->save(); $catelist = Category::getDropList(1); $model = new Blog(); $criteria = new CDbCriteria(); //查询条件 $criteria->addCondition("is_show=1"); //排序 $criteria->order = 'id DESC'; $criteria->limit = 5; $recent = $model->findAll($criteria); $this->render('view2', array('blog' => $blog, 'catelist' => $catelist, 'recent' => $recent)); }
<?php $root = $GLOBALS['root']; $footLines = getGlobal('footLines'); $posts = Blog::findAll("ORDER BY datetime DESC LIMIT 5"); ?> </section> </div> <footer> <div class='container'> <div class='row'> <div class='col-sm-4 col-xs-12'> <h2>Recent Articles</h2> <ul> <?php if (count($posts)) { foreach ($posts as $post) { $title = $post->title; $year = getDateElements("%Y", $post->datetime); $link = $root . DS . 'blog' . DS . $year . DS . snakeString($title); ?> <li><a href='<?php echo $link . DS; ?> '><?php echo $title; ?> </a></li> <?php }
/** * Get a list of blogs * * @param Request $request * @param string $params * @return void */ protected static function get($request, $params) { $blogs = Blog::findAll($request->include); static::response($blogs, 200); }
<?php $root = './../../..'; require $root . '/../app/initialize.php'; $pageTitle = 'Manage Blog'; $navSelect = 'blog'; $user = User::get('admin'); $posts = Blog::findAll("ORDER BY title ASC"); ?> <?php includeFile('site/header.php'); ?> <h2>Blog</h2> <h3>Articles</h3> <?php getAlerts(); ?> <p><a href='post.php'>Write New Post</a></p> <?php if (count($posts)) { ?> <table class="table table-hover"> <tbody> <?php foreach ($posts as $post) { ?>