从数据库生成页面
我正在寻求一些帮助,了解如何从数据库生成页面来创建项目目录,每个项目都有不同的 URL。 我似乎通过谷歌找到的都是可以为我做到这一点的产品,或者完整的电子商务解决方案。 我不要购物车! 只是一个库存。
另外,也许有人可以推荐他们最喜欢的/最好的简单登录解决方案。
非常感谢您的宝贵时间以及任何帮助、建议、评论和解决方案。
I'm looking for some help understanding how to generate pages from a database to create a catalog of items, each with different URLs. All I can seem to find through google are products that will do this for me, or full e-commerce solutions. I don't want a shopping cart! Just an inventory.
Also, perhaps someone could recommend their favorite/the best simple login solution.
Thank you so much for your time and any help, suggestions, comments, solutions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚发布了另一个问题的彻底解决方案,该解决方案非常接近-与这个问题相关。 为了您的方便,我将在这里重新发布它:
我建议使用一些 MVC(模型、视图、控制器)框架,例如 KohanaPHP。 本质上就是这样。 您正在严格面向对象的环境中工作。 Kohana 中的一个简单页面,完全由类构建,如下所示:
然后,您可以通过访问您的 url、类名和方法名来访问该页面:
http://www.mysite.com/home/ (index() 可以在 home/ 之后调用,但它是隐式的
)您开始想要引入数据库活动,您将开始使用另一个名为 模型。 这将包含与数据库交互的方法,如下所示:
请注意,我没有编写自己的查询。 Kohana 附带了一个直观的查询生成器。
该方法将从您的 Controller 中调用,这是我们在开头提到的第一个类这个解决方案。 看起来像这样:
最终,您将需要更复杂的布局,其中将涉及 HTML/CSS/Javascript。 此时,您将引入“视图”,它们只是表示层。 您无需从控制器内调用
echo
或print
,而是加载一个视图(本质上是一个 HTML 页面)并向其传递一些变量:这将加载以下“查看”
这应该足以让您开始。 使用 MVC 风格非常干净,而且使用起来非常有趣。
I just posted a thorough solution to another question that is very closely-related to this question. I'll re-post it here for your convenience:
I would suggest using some of the MVC (Model, View, Controller) frameworks out there like KohanaPHP. It is essentially this. You're working in a strictly Object-Oriented environment. A simple page in Kohana, build entirely from a class would look like this:
You would then access that page by visiting youur url, the class name, and the method name:
http://www.mysite.com/home/ (index() can be called after home/, but it's implicit)
When you start wanting to bring in database-activity, you'll start working with another Class called a Model. This will contain methods to interact with your database, like the following:
Note here that I didn't write my own query. Kohana comes with an intuitive Query Builder.
That method would be called from within your Controller, the first class that we mentioned at the beginning of this solution. That would look like this:
Eventually, you'll want more complicated layouts, which will involve HTML/CSS/Javascript. At this point, you would introduce the "Views," which are just presentation layers. Rather than calling
echo
orprint
from within the Controller, you would load up a view (an HTML page, essentially) and pass it some variables:Which would load the following "View"
That should be enough to get you started. Using the MVC-style is really clean, and very fun to work with.
有很多工具可用于围绕数据模型生成 Web 界面。 我发现 Django 非常容易使用。 基于其受欢迎程度,我确信 Ruby on Rails 是另一个可行的选择。
There's a lot of tools out there for generating a web interface around a data model. I find Django pretty easy to use. Based on its popularity, I'm sure that Ruby on Rails is another viable option.