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

[eluser]emperius[/eluser]
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:

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

is there any solution of the problem?
#2

[eluser]xwero[/eluser]
in a helper you need to use
Code:
$ci =& get_instance();
$ci->uri->segment(1);
#3

[eluser]emperius[/eluser]
thank you
everything works

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

[eluser]xwero[/eluser]
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.
#5

[eluser]emperius[/eluser]
thank you for your reply
#6

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

At my routes.php, I have:

Code:
$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:

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?
#7

[eluser]emperius[/eluser]
try the easy way Smile

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

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

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

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

[eluser]wiredesignz[/eluser]
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
#10

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

Code:
/*
* ------------------------------------------------------
*  Is there a "post_controller" hook?
* ------------------------------------------------------
*/
$EXT->_call_hook('post_controller');

Or the new version at the SVN?




Theme © iAndrew 2016 - Forum software by © MyBB