从数据库生成页面

发布于 2024-07-25 23:58:03 字数 193 浏览 5 评论 0原文

我正在寻求一些帮助,了解如何从数据库生成页面来创建项目目录,每个项目都有不同的 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 技术交流群。

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

发布评论

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

评论(2

余生再见 2024-08-01 23:58:03

我刚刚发布了另一个问题的彻底解决方案,该解决方案非常接近-与这个问题相关。 为了您的方便,我将在这里重新发布它:


我建议使用一些 MVC(模型、视图、控制器)框架,例如 KohanaPHP。 本质上就是这样。 您正在严格面向对象的环境中工作。 Kohana 中的一个简单页面,完全由类构建,如下所示:

class Home_Controller extends Controller
{
  public function index()
  {
    echo "Hello World";
  }
}

然后,您可以通过访问您的 url、类名和方法名来访问该页面:

http://www.mysite.com/home/index() 可以在 home/ 之后调用,但它是隐式的

)您开始想要引入数据库活动,您将开始使用另一个名为 模型。 这将包含与数据库交互的方法,如下所示:

class Users_Model extends Model
{
  public function count_users()
  {
    return $this->db->count_records('users');
  }
}

请注意,我没有编写自己的查询。 Kohana 附带了一个直观的查询生成器

该方法将从您的 Controller 中调用,这是我们在开头提到的第一个类这个解决方案。 看起来像这样:

class Home_Controller extends Controller
{
  public function index()
  {
    $usersModel = new Users_Model;
    $userCount = $usersModel->count_users();

    echo "We have " . $userCount . " users!";
  }
}

最终,您将需要更复杂的布局,其中将涉及 HTML/CSS/Javascript。 此时,您将引入“视图”,它们只是表示层。 您无需从控制器内调用 echoprint ,而是加载一个视图(本质上是一个 HTML 页面)并向其传递一些变量:

class Home_Controller extends Controller
{
  public function index()
  {
    $myView = new View("index");
    $usersModel = new Users_Model;
    $userCount = $usersModel->count_users();

    $myView->userCount = $userCount;
    $myView->render(TRUE);
  }
}

这将加载以下“查看”

<p>We have <?php print $userCount; ?> users!</p>

这应该足以让您开始。 使用 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:

class Home_Controller extends Controller
{
  public function index()
  {
    echo "Hello World";
  }
}

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:

class Users_Model extends Model
{
  public function count_users()
  {
    return $this->db->count_records('users');
  }
}

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:

class Home_Controller extends Controller
{
  public function index()
  {
    $usersModel = new Users_Model;
    $userCount = $usersModel->count_users();

    echo "We have " . $userCount . " users!";
  }
}

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 or print from within the Controller, you would load up a view (an HTML page, essentially) and pass it some variables:

class Home_Controller extends Controller
{
  public function index()
  {
    $myView = new View("index");
    $usersModel = new Users_Model;
    $userCount = $usersModel->count_users();

    $myView->userCount = $userCount;
    $myView->render(TRUE);
  }
}

Which would load the following "View"

<p>We have <?php print $userCount; ?> users!</p>

That should be enough to get you started. Using the MVC-style is really clean, and very fun to work with.

心凉怎暖 2024-08-01 23:58:03

有很多工具可用于围绕数据模型生成 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.

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