简体   繁体   English

Backbone.js + Twitter Bootstrap

[英]Backbone.js + Twitter Bootstrap

I have been trying to follow the guide at http://coenraets.org/directory/ 我一直试图按照http://coenraets.org/directory/上的指南进行操作

I have the contents of the "Web" folder copied onto the root of my website and the page appears just fine, I also installed his sql script into my database. 我将“Web”文件夹的内容复制到我的网站的根目录,页面显示得很好,我还将他的sql脚本安装到我的数据库中。 The search bar isn't working (probably since my SQL database requires a username and password?). 搜索栏不起作用(可能因为我的SQL数据库需要用户名和密码?)。 How do I fix this? 我该如何解决?

I am assuming that you have set up slim to run the php application that receives the javascript calls from backbone.js? 我假设你已经设置了slim来运行从backbone.js接收javascript调用的php应用程序?

Reference - https://github.com/ccoenraets/backbone-directory/blob/master/api/index.php 参考 - https://github.com/ccoenraets/backbone-directory/blob/master/api/index.php

The API directory contains a file named index.php . API目录包含名为index.php的文件。 For the php slim framework (http://www.slimframework.com/) in this application, it should contain your database IP, username and password. 对于此应用程序中的php slim框架(http://www.slimframework.com/),它应包含您的数据库IP,用户名和密码。

Lines 148 onwards in the index.php file. index.php文件中的第148行。

function getConnection() {
    $dbhost="127.0.0.1";
    $dbuser="root";
    $dbpass="";
    $dbname="directory";
    $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
}

Your server location - 98.214.131.200 - does not matter if you have set this php application on that server itself. 您的服务器位置 - 98.214.131.200 - 如果您已在该服务器上设置此php应用程序并不重要。 127.0.0.1 refers to the server localhost itself. 127.0.0.1指服务器localhost本身。

What you need to configure is the $dbuser and $dbpass (your $dbname is obviously correct since you mentioned that that's the MySQL db you created by running the provided sql script) which corresponds to the MySQL database you have set up for this demo app. 你需要配置的是$dbuser$dbpass (你的$dbname显然是正确的,因为你提到那是你通过运行提供的sql脚本创建的MySQL数据库),这对应于你为这个演示应用程序设置的MySQL数据库。

If you are using apache to run slim, make sure mod_rewrite is enabled and configure your apache virtualhost to be something like:- 如果您使用apache运行slim,请确保启用mod_rewrite并将您的apache虚拟主机配置为: -

<Directory "C:\Path\To\Your\slimphp">
    Allow From All
    AllowOverride All
</Directory>
<VirtualHost *:80>
    ServerName "slim.php"
    DocumentRoot "C:\Path\To\Your\slimphp"
</VirtualHost>

Ah, if using IIS as @vicvicvic has pointed out, use ModRewrite - http://www.micronovae.com/ModRewrite/ModRewrite.html 啊,如果使用IIS @vicvicvic指出,请使用ModRewrite - http://www.micronovae.com/ModRewrite/ModRewrite.html

You need to configure the backend in the api folder so that it actually communicates with your SQL database. 您需要在api文件夹中配置后端,以便它实际与SQL数据库通信。 Do this in the getConnection function in api/index.php : api/index.phpgetConnection函数中执行此操作:

function getConnection() {
    $dbhost="127.0.0.1";
    $dbuser="root";
    $dbpass="";
    $dbname="directory";
    $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
}

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

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