首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对象找不到!在燃料php中重定向路线后

对象找不到!在燃料php中重定向路线后
EN

Stack Overflow用户
提问于 2017-08-29 15:13:38
回答 1查看 652关注 0票数 5

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

  • 燃料,燃料
  • 日志
  • 公共的
  • tmp

在我的公用文件夹中

  • 资产
  • index.php

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

对象找不到错误

这是我的登录代码

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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"
);

这是后台控制器test_newsletter函数。

代码语言:javascript
复制
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,而是向me对象显示未找到错误。

**我读到过,我们需要把.htaccess放在我们的项目中,但我对此并不清楚。有谁能指引我**

EN

回答 1

Stack Overflow用户

发布于 2017-09-14 10:20:06

在您的web根文件夹(通常是公共/?)中尝试这个.htaccess

代码语言:javascript
复制
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]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45942700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档