You are not logged in.

  • Login

1

Sunday, May 31st 2009, 9:41pm

ZF: Nur IndexController wird angezeigt

Hallo :) ,
ich arbeite seit nicht allzu langer Zeit mit dem Zend Framework.
Aber heute ist ein Problem aufgetreten:
Es wird aus irgendeinem Grund andauernd nur der IndexController aufgerufen.
Bootstrap:

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
    define('DIRSEP', DIRECTORY_SEPARATOR);
    define('BASE_PATH', dirname(dirname(__FILE__)).DIRSEP);
    require_once 'Zend/Loader/Autoloader.php';
 
    Zend_Loader_Autoloader::getInstance();
 
    $config = new Zend_Config_Ini(BASE_PATH.'application'.DIRSEP.'config/config.ini');
    error_reporting(E_ALL);
 
    $log = new Zend_Log(new Zend_Log_Writer_Stream(BASE_PATH.'application'.DIRSEP.'logs.txt'));
    $auth = Zend_Auth::getInstance();
 
    $frontcontroller = Zend_Controller_Front::getInstance();
    $frontcontroller->throwExceptions(true);
    $frontcontroller->setBaseUrl($config->app->baseurl);
    $frontcontroller->addModuleDirectory(BASE_PATH.'application'.DIRSEP.'models');
    $frontcontroller->addControllerDirectory(BASE_PATH.'application'.DIRSEP.'controllers');
 
 
    Zend_Layout::startMvc(array('layoutPath' => BASE_PATH.'application'.DIRSEP.'views'.DIRSEP.'layouts'));
    $view = new Zend_View();
    $view->addHelperPath(BASE_PATH.'application'.DIRSEP.'views'.DIRSEP.'helpers');
    $viewrenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
    Zend_Controller_Action_HelperBroker::addHelper($viewrenderer);
 
 
    try {
        $frontcontroller->dispatch();
    }
    catch(Exception $e) {
        print $e->__toString();
        $log->log( 'Fehler: '.$e->__toString(), Zend_Log::EMERG);
    }
?>


IndexController:

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
<?php
    class IndexController extends Zend_Controller_Action
    {
        public function indexAction()
        {
            $layout = Zend_Layout::getMvcInstance();
            $layout->title = 'Index';
 
            $this->view->assign('artikel', 'Test');
        }
    }
?>


LoginController:

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
<?php
    class LoginController extends Zend_Controller_Action
    {
        public function indexAction()
        {
            $layout = Zend_Layout::getMvcInstance();
            $layout->title = 'Login';
 
            $this->view->assign('artikel', 'Anderer Test');
        }
    }
?>



Wenn ich die entsprechende Adresse mit login dran aufrufe wird immernoch der IndexController aufgerufen.
In der Errorlog steht auch kein Fehler.
?(

2

Monday, June 1st 2009, 1:26am

Hi,

also wenn du deineurl.de aufrufst gelangst du auf den Indexcontroller?
Was passiert bei deineurl.de/ndex/index oder deineurl.de/login/index

Du hast beim Frontcontroller die Module mit den Models vertauscht, die haben damit nichts zu tun.
Module enthalten Controller, wobei das optional ist. Könnte auch sein, dass es daran liegt.

Ansonsten htaccess mit den Rewrite Rules richtig eingerichet?

Welches OS nutzt du?

3

Monday, June 1st 2009, 3:02am

also wenn du deineurl.de aufrufst gelangst du auf den Indexcontroller?
Was passiert bei deineurl.de/ndex/index oder deineurl.de/login/index

Das gleiche.


Ansonsten htaccess mit den Rewrite Rules richtig eingerichet?

Source code

1
2
3
4
5
6
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Welches OS nutzt du?
Vista

4

Monday, June 1st 2009, 10:01am

Und dann setzt mal in die beiden IndexActions der Controller ein dump ein und guck dir mal den Request an. Ob du wirklich in dem jeweiligen Controller gelandet bist.

PHP Quellcode

1
Zend_Debug::dump($this->getRequest());



Wenn das alles so richtig ist, dann füge mal einen Slash in deiner RewriteRule hinzu:

PHP Quellcode

1
RewriteRule ^.*$ /index.php [NC,L]

5

Monday, June 1st 2009, 12:41pm

Und dann setzt mal in die beiden IndexActions der Controller ein dump ein und guck dir mal den Request an. Ob du wirklich in dem jeweiligen Controller gelandet bist.

PHP Quellcode

1
Zend_Debug::dump($this->getRequest());

url/login/index

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
object(Zend_Controller_Request_Http)#32 (14) {
  ["_paramSources:protected"] => array(2) {
    [0] => string(4) "_GET"
    [1] => string(5) "_POST"
  }
  ["_requestUri:protected"] => string(27) "/rt/public/login/index"
  ["_baseUrl:protected"] => string(31) "http://localhost/rt/public"
  ["_basePath:protected"] => NULL
  ["_pathInfo:protected"] => string(0) ""
  ["_params:protected"] => array(3) {
    ["controller"] => string(5) "index"
    ["action"] => string(5) "index"
    ["module"] => string(7) "default"
  }
  ["_aliases:protected"] => array(0) {
  }
  ["_dispatched:protected"] => bool(true)
  ["_module:protected"] => string(7) "default"
  ["_moduleKey:protected"] => string(6) "module"
  ["_controller:protected"] => string(5) "index"
  ["_controllerKey:protected"] => string(10) "controller"
  ["_action:protected"] => string(5) "index"
  ["_actionKey:protected"] => string(6) "action"
}


url/index/index

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
object(Zend_Controller_Request_Http)#32 (14) {
  ["_paramSources:protected"] => array(2) {
    [0] => string(4) "_GET"
    [1] => string(5) "_POST"
  }
  ["_requestUri:protected"] => string(27) "/rt/public/index/index"
  ["_baseUrl:protected"] => string(31) "http://localhost/rt/public"
  ["_basePath:protected"] => NULL
  ["_pathInfo:protected"] => string(0) ""
  ["_params:protected"] => array(3) {
    ["controller"] => string(5) "index"
    ["action"] => string(5) "index"
    ["module"] => string(7) "default"
  }
  ["_aliases:protected"] => array(0) {
  }
  ["_dispatched:protected"] => bool(true)
  ["_module:protected"] => string(7) "default"
  ["_moduleKey:protected"] => string(6) "module"
  ["_controller:protected"] => string(5) "index"
  ["_controllerKey:protected"] => string(10) "controller"
  ["_action:protected"] => string(5) "index"
  ["_actionKey:protected"] => string(6) "action"
}



Wenn das alles so richtig ist, dann füge mal einen Slash in deiner RewriteRule hinzu:

PHP Quellcode

1
RewriteRule ^.*$ /index.php [NC,L]

Gemacht, kein Unterschied.


Edit:
Ich bin dem Fehler auf die schliche gekommen.
Es lag am setBaseUrl bei der ich die Domain mit Pfad angegeben hab,
aber ohne Domain dabei geht es nun.

This post has been edited 1 times, last edit by "Zendi" (Jun 1st 2009, 2:32pm)


Similar threads

Social bookmarks