Advanced Module: view redirects to fuel login

edited January 2014 in Modules
Hi Admin

I have created an advanced module, which is working okay with the exception that the view file for the frontend wont display unless I am logged into fuel. It currently redirects to the fuel login, and once logged in it redirects back to the view file, where it is displayed correctly

Please help!

My url is example.com/index.php/account/order

route
$account_controllers = array('customers', 'orders', 'order'); foreach($account_controllers as $c) { $route[FUEL_ROUTE.'account/'.$c] = FUEL_FOLDER.'/module'; $route[FUEL_ROUTE.'account/'.$c.'/(.*)'] = FUEL_FOLDER.'/module/$1'; }

order controller
require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php'); class Order extends Fuel_base_controller { function __construct() { parent::__construct(); $this->load->library('form_validation'); $this->load->database(); $this->load->helper('form'); $this->load->helper('url'); $this->load->model('order_model'); } function index() { $this->form_validation->set_rules('name', 'Name', 'required'); $this->form_validation->set_rules('content', 'Content', ''); $this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>'); if ($this->form_validation->run() == FALSE) // validation hasn't been passed { $this->load->view('order'); } else { $form_data = array( 'name' => set_value('name'), 'content' => set_value('content') ); if ($this->order_model->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db { $this->load->view('success'); } else { echo 'An error occurred saving your information. Please try again later'; } } } }
order model
require_once(FUEL_PATH.'models/base_module_model.php'); class Order_model extends Base_module_model { function __construct() { parent::__construct(); } function SaveForm($form_data) { $this->db->insert('order', $form_data); if ($this->db->affected_rows() == '1') { return TRUE; } return FALSE; } }

Comments

  • edited 6:18PM
    If you extend the Fuel_base_controller, it will check that you are logged into the CMS. If this is a controller that you need for the front end, you can just use the normal CI_Controller to extend.
  • edited 6:18PM
    I did originally use CI_Controller, but this was giving me the following php error;

    Undefined variable: js
    and
    Undefined variable: css
  • edited 6:18PM
    I found that if I remove

    <?php echo css($css); ?> <?php echo css($js); ?>

    then the page displays fine, but I was reluctant to remove it incase it was relied upon by another part of fuel.

    Also, I also found that if I use Fuel_base_controller with
    parent::__construct(FALSE);
    then the page displays without redirecting to fuel login.
  • edited 6:18PM
    After reading a few other discussions I think I've solved it, if I extend the CI_Controller as you suggest, then using the following solved the problem with undefined variables.

    //$this->load->view('order'); //Removed $vars = array('page_title' => 'Order'); $output = $this->load->view('order', $vars, TRUE); $this->load->module_library(FUEL_FOLDER, 'fuel_page'); $this->fuel_page->initialize(); $output = $this->fuel_page->fuelify($output); $this->output->set_output($output);
    This also removed the Fuel Markers too.
Sign In or Register to comment.