如何在cakephp项目的webroot中运行php文件

时间:2016-02-20 11:35:35

标签: php cakephp cakephp-2.0

我想运行php文件,它放在cakephp 2.5项目的webroot文件夹中。 在运行时我得到下面给出的错误 enter image description here

这里nghome是放在项目webroot中的文件夹,我想在webroot / nghome / database.php中执行一个database.php文件但是在执行该文件的时候我收到错误,它说的是nghome控制器找不到。

任何帮助或建议将不胜感激,提前感谢

4 个答案:

答案 0 :(得分:1)

无需在htaccess或其他任何地方进行任何更改,只需在webroot中创建一个php文件database.php即可从浏览器访问example.com/database.php

file path - app/webroot/filename.php
access from browser - example.com/filename.php

file path - app/webroot/somedir/filename.php
access from browser - example.com/somedir/filename.php

file path - app/webroot/somedir/subdir/filename.php
access from browser - example.com/somedir/subdir/filename.php

答案 1 :(得分:1)

我终于通过使用以下代码

更新webroot文件夹下的.htaccess文件来实现此目的
SelectedValue

答案 2 :(得分:0)

检查你的.htaccess文件是否在webroot文件夹中工作

nghome/database.php

此行<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BindGridView._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowEditing="OnRowEditing" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowUpdating="GridView1_RowUpdating"> <Columns> <asp:TemplateField HeaderText="Name1"> <ItemTemplate> <asp:Label ID="lblName1" runat="server" Text='<%# Eval("Name1")%>' /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtUName1" runat="server" Text='<%# Eval("Name1")%>' /> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name2" > <ItemTemplate> <asp:Label ID="lblName2" runat="server" Text='<%# Eval("Name2")%>' /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtUName2" runat="server" Text='<%# Eval("Name2")%>' /> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name3" > <ItemTemplate> <asp:Label ID="lblName3" runat="server" Text='<%# Eval("Name3")%>' /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtUName3" runat="server" Text='<%# Eval("Name3")%>' /> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Country"> <ItemTemplate> <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country")%>' /> </ItemTemplate> <EditItemTemplate> <asp:HiddenField ID="hdnCountry" runat="server" Value='<%#Eval("country") %>' /> <%-- <asp:TextBox ID="txtCountry" runat="server" Text='<%# Eval("Country")%>' />--%> <asp:DropDownList ID="DrpDownList1" runat="server" > <asp:ListItem>India</asp:ListItem> <asp:ListItem>United States</asp:ListItem> <asp:ListItem>France</asp:ListItem> <asp:ListItem>Russia</asp:ListItem> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkButton1" Text="Edit" runat="server" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>' /> </ItemTemplate> <EditItemTemplate> <asp:LinkButton ID="LinkButton2" Text="Update" runat="server" CommandName="Update"/> <asp:LinkButton ID="LinkButton3" Text="Cancel" runat="server" OnClick="OnCancel" /> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </form> </body> </html> 负责执行现有文件。 并请求包含文件名using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace BindGridView { public partial class _Default : System.Web.UI.Page { public List<Employee> lstEmp = new List<Employee>(); protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { BindGrid(); } } protected void BindGrid() { List<Employee> lstEmp = ReturnList(); GridView1.DataSource = lstEmp; GridView1.DataBind(); } protected void OnRowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = 0; BindEdit(Session["Name"].ToString()); } protected void OnCancel(object sender, EventArgs e) { GridView1.EditIndex = -1; this.BindGrid(); } private void BindEdit(string id) { List<Employee> lstEmp = ReturnList(); lstEmp = new List<Employee>(lstEmp.Where(x => x.Id.ToString() == id).ToList()); GridView1.DataSource = lstEmp; GridView1.DataBind(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "Edit")//redirect to MangeRulepage and set query string Mode variable to 'EDIT' { //BindEdit(e.CommandArgument.ToString()); Session["Name"] = e.CommandArgument.ToString(); } } catch (Exception ex) { throw ex; } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow && GridView1.EditIndex == e.Row.RowIndex) { DropDownList ddl = (DropDownList)e.Row.FindControl("DrpDownList1"); HiddenField hdnval = (HiddenField)e.Row.FindControl("hdnCountry"); if (ddl != null) { ddl.Items.FindByValue(hdnval.Value).Selected = true; } } } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //GridView1.EditIndex = -1; TextBox tb = (TextBox)GridView1.FindControl("txtUName1");// Not getting object *tb* in case of update if (tb != null) { string text = tb.Text; } } public class Employee { public int Id { get; set; } public string Name1 { get; set; } public string Name2 { get; set; } public string Name3 { get; set; } public string Country { get; set; } } private List<Employee> ReturnList() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") }); dt.Rows.Add(1, "1,2,3", "United States"); dt.Rows.Add(2, "", "India"); dt.Rows.Add(3, "4,5,6", "France"); dt.Rows.Add(4, "", "Russia"); for (int i = 0; i < dt.Rows.Count; i++) { Employee emp = new Employee(); emp.Id = Convert.ToInt32(dt.Rows[i]["Id"]); emp.Name1 = dt.Rows[i]["Name"].ToString(); emp.Country = dt.Rows[i]["Country"].ToString(); lstEmp.Add(emp); } return lstEmp; } } }

的完整路径

答案 3 :(得分:0)

您可以将您的文件放在webroot中的nghome文件夹中,然后点击带有文件名的URL,从webroot运行您的php文件。

http://www.example.com/nghome/filename.php