简体   繁体   English

如何在Laravel4中的管理控制器上调用BaseController方法而无需反斜杠?

[英]How to call BaseController methods on admin controller in laravel4 without backslash?

I have admin following structure: 我有管理员以下结构:

Controller->admin->logincontroller
Model->admin->
View->admin->

I have used basecontroller using backslash like 我已经使用basecontroller使用反斜杠像

namespace admin;
class LoginController extends \BaseController {

However I need to place backslash on every method of base controller like as 但是我需要在基本控制器的每种方法上加上反斜杠,例如

return \View::make('test'); //instead of return View::make('');
 \Input::get('test') // instead of Input::get('username');
\Session::put() //Instead of Session::put();
etc...

So what is solutions to access method without backslash before every method repeatability. 那么在每种方法可重复性之前没有反斜杠的访问方法的解决方案是什么。

You can use method direct without '\\' into latest version. 您可以使用直接方法而不将'\\'转换为最新版本。 No need to add '\\' before method into controller. 无需在方法之前将“ \\”添加到控制器中。

This is because you use the namespace admin. 这是因为您使用名称空间admin。 Now he will search the methods inside the admin namespace and not withing the global namespace. 现在,他将在admin名称空间内而不是在全局名称空间内搜索方法。

You could also define the fullpath of those functions if you want to avoid \\ but what \\ does is saying "use the global namespace path" instead of the defined above namespace. 如果要避免使用\\也可以定义这些函数的完整路径,但是\\所做的只是说“使用全局名称空间路径”,而不是上面定义的名称空间。

namespace fallback in PHP PHP中的名称空间回退

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM