Permalink
Browse files

fix bug in categories model/db

- add slug field
- fix hardcoded table name

clean whitespace
  • Loading branch information...
1 parent 71a32a7 commit 8b4647bac4440173d21737de500538a713d21cc2 @jackboberg jackboberg committed May 14, 2012
Showing with 26 additions and 22 deletions.
  1. +11 −11 controllers/articles.php
  2. +14 −10 migrations/001_top_articles_init.php
  3. +1 −1 models/Article.php
View
@@ -61,11 +61,11 @@ public function _remap($method, $params = array())
}
//check for category
$categories = array();
- if ( ! empty($params))
+ if ( ! empty($params))
{
- if ( ! is_numeric($params[0]) && $params[0] != 'index')
+ if ( ! is_numeric($params[0]) && $params[0] != 'index')
{
- $categories[] = array_shift($params);
+ $categories[] = array_shift($params);
}
// clear params if default method call
if ( $params[0] == 'index')
@@ -107,22 +107,22 @@ private function view($params)
show_404();
}
$this->document
- ->title($article->title)
+ ->title($article->title)
->data('article', $article)
->build('articles/article_view');
}
-
+
// --------------------------------------------------------------------
/**
* categories
*
- * @access public
- *
+ * @access public
+ *
* @return void
**/
public function categories()
- {
+ {
$params = $this->uri->segment_array();
array_shift($params);
$page = 1;
@@ -162,7 +162,7 @@ private function paginated($categories, $dates = array(), $page = 1)
$start = date_create(implode('-', $dates), $TZ);
$end = clone $start;
$end->modify('+1 year');
-
+
$this->document->title($start->format('Y'));
break;
case 2:
@@ -187,7 +187,7 @@ private function paginated($categories, $dates = array(), $page = 1)
$start = $end = NULL;
break;
}
- // get a page of articles
+ // get a page of articles
$per_page = config_item('articles_per_page');
$config = array(
'start' => $start,
@@ -216,7 +216,7 @@ private function paginated($categories, $dates = array(), $page = 1)
// output the index
$page_data = array(
'articles' => $result->articles,
- 'categories' => $categories
+ 'categories' => $categories
);
$this->document
->data($page_data)
@@ -15,18 +15,18 @@ public function up()
$this->add_articles();
$this->add_categories();
}
-
+
// --------------------------------------------------------------------
-
+
/**
* add_articles
*
- * @access public
- *
+ * @access public
+ *
* @return void
**/
public function add_articles()
- {
+ {
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
@@ -70,18 +70,18 @@ public function add_articles()
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('articles');
}
-
+
// --------------------------------------------------------------------
/**
* add_categories
*
- * @access public
- *
+ * @access public
+ *
* @return void
**/
public function add_categories()
- {
+ {
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
@@ -94,6 +94,10 @@ public function add_categories()
'constraint' => '50',
'null' => FALSE,
),
+ 'slug' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => '120',
+ ),
'parent_category_id' => array(
'type' => 'INT',
'constraint' => '11',
@@ -118,7 +122,7 @@ public function add_categories()
public function down()
{
$this->dbforge->drop_table('articles');
- $this->dbforge->drop_table('categories');
+ $this->dbforge->drop_table('article_categories');
}
// --------------------------------------------------------------------
View
@@ -169,7 +169,7 @@ public static function paginated($config)
$cat_queries = array();
foreach ($categories as $category)
{
- $cat_queries[] = 'categories.slug = ?';
+ $cat_queries[] = 'article_categories.slug = ?';
$conditions[] = $category;
}
$queries[] = implode(' OR ',$cat_queries);

0 comments on commit 8b4647b

Please sign in to comment.