gpt4 book ai didi

php - 找不到对象!在 Fuel php 中重定向路由后

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:49:13 25 4
gpt4 key购买 nike

下面是我的fuelphp项目的目录结构

  • 燃料
  • 日志
  • 公开
  • tmp

在我的公共(public)文件夹中

  • Assets
  • index.php

当我点击基本 URL 以外的任何 URL 时,它会抛出以下错误

找不到对象错误

这是我的登录码

public function action_index(){

$html = new Template();

if(Session::get("logged_in")){

Response::redirect('/test-newsletter');

exit(0);
}
// die("in ifss");
if(Input::post()){

$username = Input::post('username','');
$password = Input::post('password','');

if($username === "username" && $password === "password") {

Session::set('logged_in', true);

Response::redirect('/test-newsletter');

}else{
$html->assign('message','Wrong username or password');
}

}

return $html->fetch('login.tpl');

}

这是我的 routes.php

<?php

return array(

"_root_" => "default/index",
"logout" => "default/logout",
"_404_" => "default/404",
"time" => "default/time",
"test" => "default/test",

"birthdays" => "backstage/birthdays",
"earned-status" => "backstage/earned_status",
"nearly-new-status" => "backstage/nearly_new_status",
"placed-order" => "backstage/placed_order",
"user-history" => "backstage/user_history",
"test-newsletter" => "backstage/test_newsletter",
"preview-email" => "backstage/preview_email",

"view-email/:id" => "backstage/view_email",

"api/set-date" => "backstage/api_set_date"
);

这是 Backstage Controller test_newsletter 函数

public function action_test_newsletter(){
die("here");
$submitted = Input::post("submit", false);
$points = Input::post("points", "");
$email = Input::post("email", "");
$type = Input::post("type", "");

$html = new Template();
$html->assign("points", $points);
$html->assign("email", $email);
$html->assign("type", $type);
$html->assign("message", "");

if($submitted){
$testService = new TestService(trim($type), trim($email), trim($points));

if($testService->isValid()){
$testService->processEmail();
$html->assign("message", "Email Sent!");

}else{
$html->assign("message", $testService->getErrorMesssage());
}
}

return $html->fetch("test_newsletter.tpl");
}

但是登录后它不会显示 test_newsletter 而是向我显示未找到对象错误。

** 我读到我们需要将 .htaccess 放在我们项目的某个地方,但我不清楚。任何人都可以指导我**

最佳答案

在您的网络根文件夹(通常是 public/?)中尝试这个 .htaccess:

RewriteEngine On

# The following rule tells Apache that if the requested filename
# exists, simply serve it.

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]


# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.

RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

关于php - 找不到对象!在 Fuel php 中重定向路由后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45942700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com