• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get controller and method in view

#1
Hy  there . How to get current controller  and method from view file ?
Reply

#2
The only way I managed to echo the Controller name in the View file was to set the following in the controller:

// controller
$data['controllername'] = 'Home'; // has to be hardcoded

// View
echo $controllername;
CI4 Develop Site - progressing nicely - Thank you Smile
https://johns-jokes.cf/pictures

Reply

#3
Using   Services::router ?
/**
* Returns the name of the matched controller.
*
* @return mixed
*/
public function controllerName()
{
return $this->translateURIDashes
? str_replace('-', '_', $this->controller)
: $this->controller;
}

//--------------------------------------------------------------------

/**
* Returns the name of the method to run in the
* chosen container.
*
* @return mixed
*/
public function methodName(): string
{
return $this->translateURIDashes
? str_replace('-', '_', $this->method)
: $this->method;


From codeigniter class but how to get protected controller and action from Codeigniter class ? 
$this->router = Services::router($routes);

$path = $this->determinePath();

$this->benchmark->stop('bootstrap');
$this->benchmark->start('routing');

ob_start();

$this->controller = $this->router->handle($path);
$this->method     = $this->router->methodName();

// If a {locale} segment was matched in the final route,
// then we need to set the correct locale on our Request.
if ($this->router->hasLocale())
{
$this->request->setLocale($this->router->getLocale());
}

$this->benchmark->stop('routing');

return $this->router->getFilter();
}
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.