Object not found! error 404 xamp

Asked

Viewed 630 times

-1

In this project I’m having trouble finding the route /admin I created, accessing the site index('/') the route that was set works normally, however access the admin index('/admin') the file is not found. Code: Page index

<?php 

require_once("vendor/autoload.php");

use \Slim\Slim;
use \Hcode\Page;
use \Hcode\PageAdmin;

$app = new Slim();

$app->config('debug', true);

$app->get('/', function() {

    $page = new Page();
    $page->setTpl("index");


});

$app->get('/admin', function() {

    $page = new PageAdmin();
    $page->setTpl("index");


});

$app->run();

 ?>

Page class (provides template to index):

<?php 

namespace Hcode;

use Rain\Tpl;

class Page {

    private $tpl;
    private $options = [];
    private $defaults = [
        "header"=>true,
        "footer"=>true,
        "data"=>[]
    ];

    public function __construct($opts = array(), $tpl_dir = "/views/")
    {

        $this->options = array_merge($this->defaults, $opts);
...

Pageadmin class (provides template to page /admin):

<?php

namespace Hcode;

class PageAdmin extends Page{

    public function __construct($opts = array(), $tpl_dir = "/views/admin/"){
        parent::__construct($opts, $tpl_dir);
    }

}

I was able to access the Page and Pageadmin class by the index('/') route, however, by the admin('/admin') route the following object error not found Error 404 is returned.

2 answers

0

It speaks Xará, all right? I managed to run, but I did not use the class Extend (inheritance), I’m posting because it may be that more people are at the same point that I was, so basically I re-read the Pageadmin similar to the Page, but changing the tpl_dir. Basically a redudancia, but that allowed me to continue in the course.
I hope it helps you if you want to return to class. A Hug.

<?php 

namespace Controller; //Substitua Controller por Hcode caso vc tenha feito igual ao curso

use Rain\Tpl;

class PageAdmin {

    private $tpl;
    private $options = [];
    private $defaults = [
        "data"=>[]
    ];

    public function __construct($opts = array()){

    $this->options = array_merge($this->defaults, $opts);

    $config = array(
    "tpl_dir"       => "views/admin/",
    "cache_dir"     => "views-cache/",  
    "debug"         => false
    );

    Tpl::configure( $config );

    $this->tpl = new Tpl;

    $this->setData($this->options["data"]);

    $this->tpl->draw("header");

    }

    private function setData($data = array()){

    foreach ($data as $key => $value) {

        $this->tpl->assign($key, $value);
    }
}

    public function setTpl($name, $data = array(), $returnHTML = false){

        $this->setData($data);

        return $this->tpl->draw($name, $returnHTML);
    }

    public function __destruct(){

        $this->tpl->draw("footer");

    }

}

?>

NOTE: It uses "tpl_dir" => $_SERVER['DOCUMENT_ROOT'].$tpl_dir, But in mine it didn’t work, so I left in the simplified form.

OBSERVATIO2: Include the "debug"=> false, without the same did not work.

0

Good morning, I’m in the same trouble, stuck for two days to tell you the truth. I noticed that it is a route problem, because if you change the index.php remove the /admin, it can access the administrative, but to access the index of the site.

$app->get('/(withdrew admin)', Function() {

$page = new PageAdmin(); 

$page->setTpl("index");

});

Either he is unable to access the "views/admin/index.html" subfolder or there is some error in the page.php page, because pageadmin.php just inherits it from the same page.php.

If you have managed to solve, could post the solution?

I will continue researching and testing, in case I can solve and this topic is still open, I inform you the resolution. A hug.

  • I haven’t solved it yet, I haven’t even continued this project because of this problem, but in the future I’ll try to solve it, if I can put it here. Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.