Welcome Guest, Not a member yet? Register   Sign In
Problems with uri routing

I made a function in the helper for the information output depending on the url
this helper is loaded automatically

however when i try to get current segments in the url (like $this->uri->segment(1)) i get a bug:

Fatal error: Using $this when not in object context in

is there any solution of the problem?

in a helper you need to use
$ci =& get_instance();

thank you
everything works

however i don't really understand how it works. Could you please explain? Smile

the functions in helpers are not in a class they are loose functions like the native php functions. They don't belong to any class that is why you can use them everywhere.

the $this-> variable is used to select a variable or a function, in a class called method, in the class or a parent class.

thank you for your reply

[eluser]Edemilson Lima[/eluser]
I am having a problem with a routing...

At my routes.php, I have:

$route['([a-z]+)/([0-9]+)'] = "$1/details/index/$2";

If I try to access something like: http://www.site.com/products/details/index/3
It works fine.
But, if I do it by the route: http://www.site.com/products/3
It calls products/details/index, but does not send the id code:

A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Details::index()
Filename: products/details.php
Line Number: 11

"products" is a folder, "details" is the controller and "index" is its default function.

Any ideas?

try the easy way Smile

$route['details/:num'] = "details";

[eluser]Edemilson Lima[/eluser]
I think it should be:

$route['products/:num'] = 'products/details';

I did try this too, but it doesn't work. Anyway, it should work with a regexp.

I think theres a bug here?

I had the same problem.

uri->rsegment[2] gets dropped if you route into a controllers sub-directory

See line #224 - system/codeigniter/CodeIgniter.php

[eluser]Edemilson Lima[/eluser]
This line?

* ------------------------------------------------------
*  Is there a "post_controller" hook?
* ------------------------------------------------------

Or the new version at the SVN?

Theme © iAndrew 2016 - Forum software by © MyBB