Welcome Guest, Not a member yet? Register   Sign In
How to replicate forcetype?
#1

[eluser]chobo[/eluser]
I have some web pages that I am trying to put into codeigniter, but I'm not sure how to do it. My old pages used apache force type, so one page would check different urls and load different results based on those urls. I'm trying to do something similar in codeigniter, but if you add to the url it treats that as a controller or part of it and gives you an error. Is there anyway around this behaviour? Thanks in advance.
#2

[eluser]chobo[/eluser]
I sort of got it to work be specifying routing in the route.php file. I haven't had time to try and fully implement it yet, I should know by tomorrow or Wednesday. Anyways, does anyone know how the author of bamboo invoice does his routing? If you load up the report and click the second quarter link it goes from.

http://www.bambooinvoice.org/reports

to

http://www.bambooinvoice.org/reports/dat...2007-06-30

He didn't change his routing.php file... I have no idea how he does this? Any help is appreciated, thanks.
#3

[eluser]Michael Wales[/eluser]
I've never used BambooInvoice but to me that simply looks like a Controller named reports and a method named dates - for example:

Code:
<?php
  class Reports extends Controller {
    function index() {
      // The first link you are talking about
    }

    function dates($start, $end) {
      // The second link you are talking about
    }
  }
?>

I'm honestly not very sure what you are looking for, but here's a bit more that will hopefully help you out.

I am currently working on an application that allows users to take a survey anonymously - I am use the _remap() function within the controller to do some of my routing (therefore, not having to edit the routing file):

Code:
<?php
  class Poll extends Controller {
    function _remap($method) {
      if (($method >= 1) && ($method <= 10)) {
        $this->question($method);
      } else {
        $this->default_method();
      }
    }

    function index() {
      // If there is no # between 1 and 10 given, show this
    }

    function question($id) {
      // Would be called for URI's formatted as: domain.com/poll/#
      // Where # is between 1 and 10
    }
  }
?&gt;

On a side note - it's been forever since I tried, do double-operator comparisons work in PHP. For instance, could I use:
Code:
if (1 <= $method >= 10) {
}

Might have to test that when I get back on a dev machine.
#4

[eluser]chobo[/eluser]
Ya, I was trying to figure out how the dates() method can produce a link like 2007-04-01/2007-06-30 without changing anything in the routing. If I try something like that without going into the routing.php file it will look for a controller, so I'm not sure whats going on in there.
#5

[eluser]Michael Wales[/eluser]
I still don't understand what you mean...

Create a view index.php:
Code:
&lt;?= anchor('reports/dates/2007-04-01/2007-06-030', 'Click Me'); ?&gt;

Create a controller reports.php:
Code:
&lt;?php
  class Reports extends Controller {
    function index() {
      $this->load->view('index');
    }

    function dates($start, $end) {
      echo 'Start: ' . $start . '<br />' . 'End: ' . $end;
    }
  }
?&gt;

No routing is involved - it's just URI segments.
#6

[eluser]chobo[/eluser]
Oh, I didn't know you could use the anchor tag to make urls like that. Normally you need a controller that matches the path, otherwise it gives you an error that it can't find the controller or its method. Thanks a lot for explaining it to me!
#7

[eluser]Derek Allard[/eluser]
Hey chobo.

If you grab the code of Bamboo (I released it all open source) you can see it for yourself, but in a nutshell walesmd got it. In fact, the first quarter, second quarter, etc dates are hardcoded exactly like that. I find hard-coding urls for pregenerated results helpful often actually Wink
#8

[eluser]chobo[/eluser]
I was kind of thrown off because of the way routing is handled in CI. Like if you have something like http://site/products/widgets/blue/3, I thought you actually needed a controller that matched that whole path. Since by default the "products" segement is the controller name, then "widgets" is the method, and after that I'm not sure how CI handles it. I guess I just need to play around with that.
#9

[eluser]Michael Wales[/eluser]
Everything after the method can either be passed to the method or you can use the URI class to retrieve segments. These two function would produce the exact same results:

Code:
function widgets($color, $id) {
}

Code:
function widgets() {
  $color = $this->uri->segment(3);
  $id = $this->uri->segment(4);
}
#10

[eluser]chobo[/eluser]
I see now that I was missing out on some very basic fundamentals in CI. After reading walesmd I quickly browsed the beginning area of the user guide, and found exactly what he is referring to. Thanks for hammering the concept home walesmd, and for providing the examples Smile




Theme © iAndrew 2016 - Forum software by © MyBB