Welcome Guest, Not a member yet? Register   Sign In
Is there a way to get the controller name inside a view?
#1

[eluser]jstuardo[/eluser]
I have created a PHP that contains common functions I have to use in a control panel I am programming. One function is called display_toolbar($title).

That function displays the title of the current page and a toolbar with some buttons, for example, "Create" or "Delete".

The anchor for those operations is different depending the controller. For example, if the toolbar is shown in the users list page, "Create" operation has to be:

Code:
anchor('usuario/create', '<img src="img.jpg" alt="Crear" />')

But for the list shown in events list page, "Create" operation has to be:

Code:
anchor('evento/create', '<img src="img.jpg" alt="Crear" />')

Is there a way to get the controller segment dinamically depending which controller was loaded?

Thanks in advance
Jaime
#2

[eluser]Dam1an[/eluser]
you can get the name of the controller using
Code:
$this->router->class;
#3

[eluser]SpooF[/eluser]
Code:
get_class($this)

Will return the name of the class that $this belongs too. Only problem is that will return the first class the controller extends.

Code:
&lt;?php
class A {
    function foo() {
      return get_class();
    }
}
class B extends A {
   function bar() {
      return get_class();
   }
}
$instance = new B();
echo $instance->bar(); //Prints 'B';
echo $instance->foo(); //Prints 'A';
?&gt;
#4

[eluser]TheFuzzy0ne[/eluser]
Code:
$this->uri->rsegment(1);

Does pretty much the same thing too. Ooh, aren't you just spoilt for choice. Tongue
#5

[eluser]jstuardo[/eluser]
Thanks! it worked.

Jaime

[quote author="Dam1an" date="1244847379"]you can get the name of the controller using
Code:
$this->router->class;
[/quote]




Theme © iAndrew 2016 - Forum software by © MyBB