Question about routing...

edited June 2011 in Modules
I seem to be having an issue with routing, and I am ending up at the 404 page when I am sure I should not be.

What I have done is based on the News module from the "Creating a Page" tutorial.
Everything was going great until I changed the view/model names to match my project.

Now the if statement in the view file that checks to see if the extra uri segment is present will send me to a 404 if the extra uri segment is there. I do not call any 404 redirects in the view file, so I'm not exactly sure where I am being redirected from.

For example:
site.com/get-involved/join-the-army -> works as it should
site.com/get-involved/join-the-army/$urlFromDB -> Redirects to 404 page

And I know that $urlFromDB exists in the database.

Any idea what I am doing wrong that could be causing this?

All relevant code is below.


DB Table >
************************************************************
CREATE TABLE `army_pages` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`content` text COLLATE utf8_unicode_ci NOT NULL,
`published` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes',
PRIMARY KEY (`id`),
UNIQUE KEY `permalink` (`url`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;



models/army_pages_model.php >
************************************************************
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once(FUEL_PATH.'models/base_module_model.php');

class Army_pages_model extends Base_module_model {

public $required = array('title');

function __construct() {
parent::__construct('army_pages'); // table name
}

function list_items($limit = NULL, $offset = NULL, $order = 'desc') {
$this->db->select('id, title, url, published');
$data = parent::list_items($limit, $offset, $col, $order);
return $data;
}

function on_before_clean($values) {
if (empty($values['url'])) $values['url'] = url_title($values['title'], 'dash', TRUE);
return $values;
}

function form_fields($values = array()) {
$fields = parent::form_fields();
return $fields;
}

function _common_query() {
parent::_common_query(); // to do active and published
}
}

class Army_pages_item_model extends Base_module_record {
}
?>



views/_variables/join-the-army.php
************************************************************

<?php

$vars['get-involved/join-the-army'] = array('view' => 'get-involved/join-the-army');
$pages['get-involved/join-the-army/:any'] = array('view' => 'get-involved/join-the-army');

?>



views/get-involved/join-the-army.php
************************************************************
<?php
$url = uri_segment(3);
if (!empty($url)) {

$custom_army = fuel_model('army_pages', array('find' => 'one', 'where' => array('url' => $url), 'return_method' => 'object'));
#if (empty($news_item)) show_404();

}else{

//$default = fuel_model('army_pages', array('return_method' => 'object'));
$default = 'Define default messaging here.';
}
?>

Join the Army

<?php if (!empty($custom_army)) : ?>

CUSTOM army messaging.

<?php else: ?>

DEFAULT army messaging.

<?php endif; ?>



Thanks.

Signup form goes here

Comments

  • edited 6:18PM
    Alright, so I think I've figured it out.

    All I had to do was move this line from 'views/_variables/join-the-army.php' to 'views/variables/global.php' ->
    $pages['get-involved/join-the-army/:any'] = array('view' => 'get-involved/join-the-army');


    Is there a naming convention for the variables files that perhaps I didn't follow?
  • edited 6:18PM
    Your solution is correct. You need to specify the view for those pages (you can add the $pages variable to the join-the-army.php file too if you just want it to load in that section). Also, you can set the variable 'find_view' in join-the-army.php and it should find the view file.
    $vars['find_view'] = TRUE;
Sign In or Register to comment.