Autor Zpráva
steve
Profil *
Dobry den. Pomocou tutorialu, som si spravil/prisposobil jeden taky velmi jednoduchy MVC php framework. Ide o to, ci by ste ho len tak zrychla skontrolovali, povedali co tam je zle, co spravit inak. Ide este o jednu vec, na niektorych serveroch mi skoro vobec nechce ist, pise to rozne chyby pri require resp., u jedneho serveru mi ked zadam normalnu adresu webu napr. nieco.sk/mvc tak mi to vypise Prístup bol odmietnutý (Chyba 403), ale uz ked zadam nieco.sk/mvc/blog/ tak uz to ide a normalne nacita dany controller. Inde mi to zas hadze takuto chybu: Fatal error: require_once() [function.require]: Failed opening required 'base.php' (include_path='.:/usr/local/lib/php') /index.php on line 44... Ale na localhoste mi to bezi bezproblemovo. Neviete mi poradit? Tu su kody:
.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /mvc/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

 <IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

index.php
<?php

 //Define our site URL
define("BASE_PATH", " http://nieco.sk");

 //Define our basepath
$path = "/mvc";

 //Take the initial PATH.
$url = $_SERVER['REQUEST_URI'];
$url = str_replace($path,"",$url);

 //creates an array from the rest of the URL
$array_tmp_uri = preg_split('[\\/]', $url, -1, PREG_SPLIT_NO_EMPTY);

 //Here, we will define what is what in the URL
$array_uri['controller']     = $array_tmp_uri[0]; //trieda
$array_uri['method']    = $array_tmp_uri[1]; //funkcia
$array_uri['var']        = $array_tmp_uri[2]; //var

 if(!isset($array_uri['controller'])) $array_uri['controller']="index";

 //Load our base API
require_once("base.php");

 //loads our controller
$application = new Application($array_uri);
$application->loadController($array_uri['controller']);

    

 ?>         

base.php
<?php if (!defined('BASE_PATH')) exit('Not allowed.');
    

 class Application
{
    private $uri;
    private $model;

  
     function __construct($uri)
    {
        $this->uri = $uri;
    }

   function loadLibrary($library){
     $lib = "application/libraries/".$library.".php";
     if(!file_exists($lib)) die("Zadana knihovna neexistuje");
     require_once($lib);
     $libini = new $library();
     return $libini;
  }
  
  
     function loadController($class)
    {
        
     $file = "application/controller/".$this->uri['controller'].".php";

         if(!file_exists($file)) die("Zadana stranka neexistuje");

         require_once($file);

         $controller = new $class();

         if(method_exists($controller, $this->uri['method']))
        {
            $controller->{$this->uri['method']}($this->uri['var']);
        } else {
            $controller->index();
        }
    }

     function loadView($view,$vars="")
    {
        if(is_array($vars) && count($vars) > 0)
            extract($vars, EXTR_PREFIX_SAME, "wddx");
        require_once('application/view/'.$view.'.php');
    }

     function loadModel($model)
    {
        require_once('application/model/'.$model.'.php');
        $this->$model = new $model;
    }
}


 ?>

Bol by som vam velmi vdacny kebyze sa na to pozriete a "vypychnete" zle veci, chyby atd. Dakujem

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: