codeigniter、管理系统和自动加载

发布于 2024-10-12 10:17:29 字数 161 浏览 6 评论 0原文

你好,我正在开发一个项目,我有一个页脚和一个侧边栏,我想从数据库加载一些信息,我该怎么做才能在所有页面上加载相同的信息。

我想制作一个管理系统,我应该怎么做?我是否需要安装新的 codeigniter 或者我可以在我的控制器、模型和视图地图中创建一个新地图吗?

你们怎么做的?

Hello im working on a project and i have a footer and a sidebar that i want to load some information from the database, how can i do so it load the same on all pages.

i want to make a admin system to, how should i do that?, do i need to have a new codeigniter instillation or can i just create a new map in my controller,model and view maps ?.

how you guys doing it?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫烠⑼条掵仅有一顆心 2024-10-19 10:17:30

我的方法是创建一个 MY_Controller,然后将所有通用逻辑放入其中,然后所有其他控制器都扩展您的 MY_Controller。这使您不必重复获取内容并在控制器内一遍又一遍地定义和编写相同的代码。请参阅 Phil Sturgeon 关于基类并保持干燥的文章

为了模板化您的网站(包括管理面板),Phil Sturgeon 还创建了一个简单的模板库,它允许你可以在你的网站上有不同布局的主题,你可以在它们之间切换,等等。

至于创建管理面板,菲尔也写了一篇关于这个主题的文章,他详细介绍了你可以使用的各种方法开发一个管理面板,哪种方法最好等等。文章中的一些评论也非常有帮助。请在此处阅读他的管理文章

The way I would go about it is create a MY_Controller and then put all of your generic logic inside of it and then all of your other controllers extend your MY_Controller. This saves you having to fetch content repeatedly and define and write the same code over and over again inside of your controllers. See Phil Sturgeon's article on base classes and keeping it DRY.

For templating your site including an admin panel, Phil Sturgeon has also created a simple template library that allows you to have themes on your site with different layouts you can switch between, etc.

As for creating an admin panel, Phil has also written a post on the subject as well and he goes into quite a bit of detail about the various ways you can develop an admin panel, which approach is best, etc. Some of the comments on the article are also very helpful too. Read his admin article here.

泼猴你往哪里跑 2024-10-19 10:17:30

我通常使用的模板方法是这样的......(这显然取决于您的设计中的侧边栏是否位于标记中的“内容”之前/之后)

<? $this->load->view('path/to/header') ?>

//content of page

<? $this->load->view('path/to/sidebar') ?>

<? $this->load->view('path/to/footer') ?>

现在,如果您要拥有变量,则需要每个视图,您都可以像在控制器的构造函数中一样全局加载它们。

$data->some_variable = $some_information;
$this->load->vars($data);

这将使 $some_variable 可用于从该控制器加载的所有视图。

管理系统只是站点/应用程序的另一个区域,仅受身份验证系统保护。您首先需要一种方法来验证用户的身份。我通常使用 Ion_Auth 作为我的首选身份验证库,并且我已经做了 关于如何在 a 中设置 Ion_auth 和“受保护”控制器的相当广泛的文章非常干净时尚。

The templating method I usually use is as such... (it obviously is dependent on whether your sidebar, in your design, comes before/after the "content" in your markup)

<? $this->load->view('path/to/header') ?>

//content of page

<? $this->load->view('path/to/sidebar') ?>

<? $this->load->view('path/to/footer') ?>

Now if you are going to have variables you will need for every view, you can load them globally like so in the constructor of your controller.

$data->some_variable = $some_information;
$this->load->vars($data);

This will make $some_variable available to all views you load from that controller.

An admin system is simply another area of your site/application that is simply protected by an authentication system. You first need a way to verify the user's identity. I generally use Ion_Auth as my preferred auth library, and I have done a fairly extensive write-up on how to set up Ion_auth and your "protected" Controllers in a very clean fashion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文