version 1.0 render view from controller with uri segments

edited March 2013 in Modules
As noted above, I'm using v1.0.

I need to snag uri segment values in a controller and use those values to build queries. Nothing new, right? I typically have used the opt-in controller method but the one I'm working in right now just has too much conditional code to leave all that in the view. So, in an effort to clear out and simplify the view I decided to place all the conditional stuff in a controller and feed all the variables to the view in the $vars array. That's how it's supposed to work, right?

In fact, I have another controller/view page in the same site that works perfectly.

So, the controller is, of course the same file name as the view and they're both in their respective folders off application/
/application/controllers/filename.php and /application/views/filename.php

In the controller I am saving the uri segs to variables. Here are the first few lines of the controller with some stuff cut out of it to simplify:

<?php class Filename extends CI_Controller { public $vars = array(); function __construct() { parent::__construct(); } function index() { $seg1 = $this->uri->segment(1); $seg2 = $this->uri->segment(2); $seg3 = $this->uri->segment(3); if (!empty($seg3)) { if (!empty($seg2)) { // do stuff here $vars['varname1']; $vars['varname2']; // have tried this both ways but still unable to pull vars into the view //$this->fuel->pages->render("filename", $vars); $this->fuel->pages->render("filename/$seg2/$seg3", $vars); } } } }

So basically, I'm unable to pass $vars from the controller to /viewfile/seg2/seg3

If I simplify the controller to:
<?php class Filename extends CI_Controller { public $vars = array(); function __construct() { parent::__construct(); } function index() { // do stuff here $vars['varname1']; $vars['varname2']; $this->fuel->pages->render("filename", $vars); } }
The variables come through to the view just fine.

What am I doing wrong?

Comments

Sign In or Register to comment.