Jump to content

Podem-me explicar porque é que isto acontece?


Recommended Posts

Posted

Então é assim

V5keVHF.png

No ficheiro que está agora selecionado tenho isto

<?php
 $url = $_GET['url'];
 echo $url;
?>

Se na barra de endereço escrever http://127.0.1.1/mvc/blarg (se escrever index ou outra coisa qualquer mostra-se o que está escrito depois de mvc/)

aparece-me na página "blarg" já que é o que estou a mandar fazer output

Depois crio outro ficheiro em controllers/index.php e meto isto

<?php
class Index {

 function __construct(){
  echo 'We are in index';
 }
}
?>

tenho que adicionar no ficheiro index.php (o que está selecionado na imagem.)

<?php
 $url = $_GET['url'];
 echo $url;
 require 'controllers/' . $url . '.php';
 $controller = new $url;
?>

se na barra de endereço escrever isto http://127.0.1.1/mvc/index

deveria aparecer escrito "indexWe are in Index"

mas o que tenho como output é só isto

Citação

Not Found

The requested URL /mvc/index was not found on this server.

Se criar em controllers o ficheiro help.php e meter lá isto

<?php
class Help{

 function __construct(){
  echo 'We are inside help';
 }
}

?>

se for a http://127.0.1.1/mvc/help já funciona como deve ser ou seja aparece "helpWe are inside help".

Ainda pensei que tivesse a mandar para o sitio errado o index mas não.

"If It Ain't Broke, Break it and build something Cooler!" Unknown

Posted (edited)

o .htaccess é o seguinte

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Edited by sEnte

"If It Ain't Broke, Break it and build something Cooler!" Unknown

Posted (edited)

juntando Options Indexes FollowSymLinks parece ter resolvido o problema.

o meu .htaccess agora está assim

RewriteEngine On

Options Indexes FollowSymLinks

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

Obrigado.

Edited by sEnte

"If It Ain't Broke, Break it and build something Cooler!" Unknown

Posted (edited)

O mais imsples será ir à raiz certo?

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

O que convem remover daqui?

Edited by sEnte

"If It Ain't Broke, Break it and build something Cooler!" Unknown

Posted

Ainda me estou a introduzir a este sistema 🙂

tenho uma pasta controladores onde crio as classes e faço extends Controller

depois noutra pasta tenho as libraries onde crio os controladores, depois noutra pasta views que é onde tenho o front-end

"If It Ain't Broke, Break it and build something Cooler!" Unknown

Posted

@yoda

Estou aberto a sugestões dos conhecedores disto 😛 eu ainda estou em fase de aprendizagem.

@HappyHippyHippo

o que meti num post anterior é o conteudo do ficheiro default em /etc/apache2/sites-available/

o que é que devo mudar então?

"If It Ain't Broke, Break it and build something Cooler!" Unknown

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.