Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [CakePHP] Adres url, Adres bez "app/webroot"
kacperix
post 3.09.2006, 16:24:20
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 30.07.2006
Skąd: okolice Elbląga

Ostrzeżenie: (0%)
-----


Witam.

Mój kolejny problem polega na tym, że gdy w kodzie strony używam przekierowania wbudowane w CakePHP, tzn.:

Kod
$this->redirect('w tym miejscu adres');


To w przypadku gdy chce przekierować stronę do adresu, np. http://jakasdomena.pl/users/login to adres ten jest zamieniany do postaci: http://jakasdomena.pl/app/webroot/users/login

Czy istnieje mozliwość aby adresy url nie zawierały "app/webroot" questionmark.gif

Pozdrawiam
Go to the top of the page
+Quote Post
nrm
post 3.09.2006, 16:45:05
Post #2





Grupa: Zarejestrowani
Postów: 627
Pomógł: 33
Dołączył: 1.05.2005
Skąd: Katowice

Ostrzeżenie: (0%)
-----


cos musiales schrzanic, mia dziala dobrze:

  1. <?php
  2. $this->redirect('/user/login');
  3. exit();
  4. ?>


Pamietaj o exicie na koncu (exclamation.gif!).


--------------------
Go to the top of the page
+Quote Post
kacperix
post 6.09.2006, 19:48:22
Post #3





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 30.07.2006
Skąd: okolice Elbląga

Ostrzeżenie: (0%)
-----


Dodałem exit() ale to i tak nie pomaga. Stale dodaje mi app/webroot. Moja wersja CakePHP: 1.1.7.3363.

Może coś w pliku konfiguracyjnym mam pokiełbasione??


  1. <?php
  2. /* SVN FILE: $Id: core.php 2951 2006-05-25 22:12:33Z phpnut $ */
  3. /**
  4.  * This is core configuration file.
  5.  *
  6.  * Use it to configure core behaviour ofCake.
  7.  *
  8.  * php versions 4 and 5
  9.  *
  10.  * CakePHP : Rapid Development Framework <http://www.cakephp.org/>
  11.  * Copyright (c) 2006, Cake Software Foundation, Inc.
  12.  * 1785 E. Sahara Avenue, Suite 490-204
  13.  * Las Vegas, Nevada 89104
  14.  *
  15.  * Licensed under The MIT License
  16.  * Redistributions of files must retain the above copyright notice.
  17.  *
  18.  * @filesource
  19.  * @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
  20.  * @link <a href="http://www.cakefoundation.org/projects/info/cakephp" target="_blank">http://www.cakefoundation.org/projects/info/cakephp</a> CakePHP Project
  21.  * @package cake
  22.  * @subpackage cake.app.config
  23.  * @since CakePHP v 0.2.9
  24.  * @version $Revision: 2951 $
  25.  * @modifiedby $LastChangedBy: phpnut $
  26.  * @lastmodified $Date: 2006-05-25 17:12:33 -0500 (Thu, 25 May 2006) $
  27.  * @license <a href="http://www.opensource.org/licenses/mit-license.php" target="_blank">http://www.opensource.org/licenses/mit-license.php</a> The MIT License
  28.  */
  29. /**
  30.  * If you do not have mod rewrite on your system
  31.  * or if you prefer to use CakePHP pretty urls.
  32.  * uncomment the line below.
  33.  * Note: If you do have mod rewrite but prefer the
  34.  * CakePHP pretty urls, you also have to remove the
  35.  * .htaccess files
  36.  * release/.htaccess
  37.  * release/app/.htaccess
  38.  * release/app/webroot/.htaccess
  39.  */
  40. // define ('BASE_URL', env('SCRIPT_NAME'));
  41. /**
  42.  * Set debug level here:
  43.  * - 0: production
  44.  * - 1: development
  45.  * - 2: full debug with sql
  46.  * - 3: full debug with sql and dump of the current object
  47.  *
  48.  * In production, the "flash messages" redirect after a time interval.
  49.  * With the other debug levels you get to click the "flash message" to continue.
  50.  *
  51.  */
  52. define('DEBUG', 1);
  53. /**
  54.  * Turn of caching checking wide.
  55.  * You must still use the controller var cacheAction inside you controller class
    .
  56.  * You can either set it controller wide, or in each controller method.
  57.  * use var $cacheAction = true; or in the controller method $this->cacheAction = true;
  58.  */
  59. define('CACHE_CHECK', false);
  60. /**
  61.  * Error constant. Used for differentiating error logging and debugging.
  62.  * Currently php supports LOG_DEBUG
  63.  */
  64. define('LOG_ERROR', 2);
  65. /**
  66.  * CakePHP includes 3 types of session saves
  67.  * database or file. Set this to your preferred method.
  68.  * If you want to use your own save handler place it in
  69.  * app/config/name.php DO NOT USE file or database as the name.
  70.  * and use just the name portion below.
  71.  *
  72.  * Setting this to cake will save files to /cakedistro/tmp directory
  73.  * Setting it to php will use the php default save path
  74.  * Setting it to database will use the database
  75.  *
  76.  *
  77.  */
  78. define('CAKE_SESSION_SAVE', 'database');
  79. /**
  80.  * If using you own table name for storing sessions
  81.  * set the table name here.
  82.  * DO NOT INCLUDE PREFIX IF YOU HAVE SET ONE IN database.php
  83.  *
  84.  */
  85. define('CAKE_SESSION_TABLE', 'cake_sessions');
  86. /**
  87.  * Set a random string of used in session.
  88.  *
  89.  */
  90. define('CAKE_SESSION_STRING', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
  91. /**
  92.  * Set the name of session cookie
  93.  *
  94.  */
  95. define('CAKE_SESSION_COOKIE', 'cookie');
  96. /**
  97.  * Set level of Cake security.
  98.  *
  99.  */
  100. define('CAKE_SECURITY', 'high');
  101. /**
  102.  * Set Cake Session time out.
  103.  * If CAKE_SECURITY define is set
  104.  * high: multiplied by 10
  105.  * medium: is multiplied by 100
  106.  * low is: multiplied by 300
  107.  *
  108.  * Number below is seconds.
  109.  */
  110. define('CAKE_SESSION_TIMEOUT', '600');
  111. /**
  112.  * Uncomment the define below to use cake built in admin routes.
  113.  * You can set this value to anything you want.
  114.  * All methods related to the admin route should be prefixed with the
  115.  * name you set CAKE_ADMIN to.
  116.  * For example: admin_index, admin_edit
  117.  */
  118. define('CAKE_ADMIN', 'admin');
  119. /**
  120.  * The define below is used to turn cake built webservices
  121.  * on or off. Default setting is off.
  122.  */
  123. define('WEBSERVICES', 'off');
  124. /**
  125.  * Compress output CSS (removing comments, whitespace, repeating tags etc.)
  126.  * This requires a/var/cache directory to be writable by the web server (caching).
  127.  * To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use Controller::cssTag().
  128.  */
  129. define('COMPRESS_CSS', false);
  130. /**
  131.  * If set to true, helpers would output data instead of returning it.
  132.  */
  133. define('AUTO_OUTPUT', false);
  134. /**
  135.  * If set to false, session would not automatically be started.
  136.  */
  137. define('AUTO_SESSION', true);
  138. /**
  139.  * Set the max size of file to use md5() .
  140.  */
  141. define('MAX_MD5SIZE', (* 1024) * 1024);
  142. /**
  143.  * To use Access Control Lists with Cake...
  144.  */
  145. define('ACL_CLASSNAME', 'DB_ACL');
  146. define('ACL_FILENAME', 'dbacl' . DS . 'db_acl');
  147. ?>


Witam!

Udało mi się rozwiązać problem w ten sposób:

W pliku controller.php bibliotek CakePHP jest funkcja odpowiadająca za przekierowywanie:

Wygląda ona następująco:

  1. <?php
  2. function redirect($url, $status = null) {
  3. 00336  $this->autoRender = false;
  4. 00337  $pos = strpos($url, '://');
  5. 00338  $base = strip_plugin($this->base, $this->plugin);
  6. 00339  if ($pos === false) {
  7. 00340  if (strpos($url, '/') !== 0) {
  8. 00341  $url = '/' . $url;
  9. 00342  }
  10. 00343  $url = $base . $url;
  11. 00344  }
  12. 00345 
  13. 00346  if (function_exists('session_write_close')) {
  14. 00348  }
  15. 00349 
  16. 00350  if ($s..........itd
  17. ?>


Zmieniłem wiersz nr 00343 na następujący:

  1. <?php
  2. 00343  $url = $url;
  3. ?>


I teraz gdy korzystam z funkcji redirect(), do adresu nie jest już dodawamy łańcuch "app/webroot"

Pozdrawiam
Go to the top of the page
+Quote Post
MiB
post 11.09.2006, 17:45:14
Post #4





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 30.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


@kacperix: hackowanie rdzenia Cake`a to nie jest dobre rozwiązanie - kiedyś zrobisz update rdzenia, zapomnisz o hacku i kilka godzin nie Twoje winksmiley.jpg

Po pierwsze - sprawdź jaką wartość ma stała 'APP_DIR' (w index.php Twojej strony).
Po drugie - sprawdź, czy adres podajesz z '/' na początku.

Pozdrawiam
Go to the top of the page
+Quote Post
kacperix
post 15.09.2006, 20:04:35
Post #5





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 30.07.2006
Skąd: okolice Elbląga

Ostrzeżenie: (0%)
-----


Racja, że jest to nie najlepszy pomysł, no ale cóż zrobić.

Cytat
Po pierwsze - sprawdź jaką wartość ma stała 'APP_DIR' (w index.php Twojej strony).
Po drugie - sprawdź, czy adres podajesz z '/' na początku.


- Stała 'app_dir' ma wartość 'app' - Ma taka być czy muszę ją zmienić aby działało przekierowanie??

- A jeżeli chodzi o adres to zawsze z '/'

Pozdrawiam
Go to the top of the page
+Quote Post
MiB
post 15.09.2006, 21:02:36
Post #6





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 30.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Hmm...

  1. <?php
  2. /**
  3.  * If you do not have mod rewrite on your system
  4.  * or if you prefer to use CakePHP pretty urls.
  5.  * uncomment the line below.
  6.  * Note: If you do have mod rewrite but prefer the
  7.  * CakePHP pretty urls, you also have to remove the
  8.  * .htaccess files
  9.  * release/.htaccess
  10.  * release/app/.htaccess
  11.  * release/app/webroot/.htaccess
  12.  */
  13. // define ('BASE_URL', env('SCRIPT_NAME'));
  14. ?>


Może nie masz mod_rewrite`a? (najlepiej odkomentuj i sprawdź jak działa strona z tym).

Pozdrawiam
Go to the top of the page
+Quote Post
kacperix
post 17.09.2006, 10:55:58
Post #7





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 30.07.2006
Skąd: okolice Elbląga

Ostrzeżenie: (0%)
-----


mod_rewrite jest zainstalowany na 100% (działam na serwerach Nazwa.pl) :roll2:

Kurcze no......jak innym to działa to i u mnie musi działać.

Czy może to być spowodowane złą konfiguracją przy instalacji CakePHP?? Albo może to jest coś na serwerach ustawione tak a nie inaczej, że to tak działa??

Ja już nie mam nerwów na tego CakePHP smile.gif Uruchamiałem go na serwerze WAMP pod Windowsem i wszystko pięknie gra, przekierowanie działa w taki sposób w jaki powinno.

A na serwie w necie (nazwa.pl), nie chce działać tak jak powinno, cały czas przy przekierowaniu przy wykorzystaniu funkcji redirect() jest dodawane do adresu: "app/webroot". MASAKRA!!! angrysmiley.gif

Witam!

Nareszcie udało mi się rozwiązać ten problem. Natknąłem się gdzieś na to (ale nie mogę sobie przypomnieć gdzie: chyba Google Groups), i było to związane z podobnym problemem. Otóż:

Do pliku .htaccess w folderze app/webroot dodałem taką linijkę kodu:

Kod
RewriteBase /


A w pliku index.php znajdującego się w tym samym folderze zmieniłem następujący kod:

Kod
if (!defined('WEBROOT_DIR')) {
                 define('WEBROOT_DIR', basename(dirname(__FILE__)));
        }


Na taki:

Kod
if (!defined('WEBROOT_DIR')) {
                 define('WEBROOT_DIR', '/');
        }


I teraz jest OK.

Ten post edytował kacperix 16.09.2006, 15:54:45
Go to the top of the page
+Quote Post
jonek
post 9.12.2006, 17:09:15
Post #8





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 9.12.2006

Ostrzeżenie: (0%)
-----


Czyli kacperix olałeś napis "do not edit below this line" czy jakoś tak on brzmi smile.gif
Miałem podobny problem. Okazało się, że to kwestia zawartości zmiennej środowiskowej PHP_SELF. Problem to chyba też po części rzecz związana z wyczesanym softem servera na home.pl bo na innych wszystko działało. Mnie pomogła zmiana tej linijki głównego pliku .htaccess (tego na samym topie struktury) z:

RewriteRule ^$ app/webroot/ [L]

na

RewriteRule ^$ app/webroot/index.php [L]

i to wszystko tongue.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 17.05.2024 - 14:27