HMVC 和文件夹中的视图 (Codeigniter)
我在 Codeigniter 中使用 Tank Auth 库和 HMVC,整个 Tank Auth mvc 文件位于其自己的名为“auth”的模块中。 Tank auth 使用以下方式加载在文件夹(auth)内找到的视图(domain.com/application/modules/auth/views/auth/login_form.php):
$this->load->view('auth/login_form', $data);
据我所知,上面的代码将在 auth 文件夹内加载 login_form.php正确地没有 HMVC。但是,对于 HMVC,我需要以下代码来加载视图:
$this->load->view('auth/auth/login_form', $data);
是否有我们应该更改的设置,以便我们不必通过(模块名称)/(视图文件夹名称)/(视图文件名)引用视图文件?或者这是完全正常的并且大多数人都是这样做的?
我必须将模块文件夹名称“auth”添加到每个 view() 函数调用中,并且如果我更改模块文件夹的名称,则必须更改所有这些,这似乎很麻烦。
I am using Tank Auth library in Codeigniter with HMVC and the entire tank auth mvc files are in its own module called 'auth'. tank auth loads a view (domain.com/application/modules/auth/views/auth/login_form.php) found inside a folder (auth) using:
$this->load->view('auth/login_form', $data);
As far as I know the above code will load login_form.php inside the auth folder properly without HMVC. However with HMVC, I need the following code to get the view to load:
$this->load->view('auth/auth/login_form', $data);
Is there a setting that we should change so we dont have to refer to the view file by (module name)/(views folder name)/(view filename) ? Or is this perfectly normal and most people does it this way?
It seems troublesome that I have to add the module folder name 'auth' to every view() function call, and change all of them should I change the name of the module folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您正在使用 模块化扩展 - HMVC:
如果您有
auth
已经设置为模块,您只需调用:文件
/views/login_form.php
将从当前模块内加载。这适用于模型、语言文件、库等。将模块视为其自己的应用程序,这是您通常会做的事情。此外,要从模块目录之外的另一个模块或控制器加载文件,您可以使用 $this->load->view('auth/login_form');
如果文件不是找到后,它会检查其他模块路径,包括默认目录。我不确定这可能是也可能不是其他 HMVC 包的工作方式 - 但这是 MX 的工作方式。
Assuming you're using Modular Extensions - HMVC:
If you have
auth
set up as a module already, you can just call:The file
/views/login_form.php
will be loaded from within the current module. This applies to models, language files, libraries etc. Think of the module as its own application, this is what you would normally do.Additionally, to load a file from another module or a controller outside the module's directory, you can use
$this->load->view('auth/login_form');
If the file is not found, it will check the other module paths including the default directory. This may or may not be the way other HMVC packages work, I'm not sure - but it's the way MX works.