Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

AutoLoader Fehler

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Dennion
Smarty Rookie


Joined: 09 Jan 2017
Posts: 5

PostPosted: Mon Jan 09, 2017 12:56 am    Post subject: AutoLoader Fehler Reply with quote

Liebe Community,

leider komme ich Aktuell nicht weiter :/ Ich benutze einen Eigenen Autoloader um meine Classen zu Includen. Dieser kommt mit Smarty aber leider garnicht zurecht und ich weiß nichtmehr weiter...

Hier mal der Autoloader

Code:

define('CLASS_PFAD', 'dcf\lib\\');
   function autoload($className){
      $className = ltrim($className, '\\');
      $fileName  = '';
      $namespace = '';
      if ($lastNsPos = strrpos($className, '\\')) {
         $namespace = substr($className, 0, $lastNsPos);
         $className = substr($className, $lastNsPos + 1);
         $fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
      }
      $fileName = str_replace("dcf\\", "", $fileName);
      $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.class.php';
      require CLASS_PFAD . $fileName;
   }
   spl_autoload_register('autoload');

Benötigt wird Smarty bei mir in der Template Class:
Code:

class Template extends Smarty {

Und Liegen tut Smarty:
dcf/lib/smarty/Smarty.class.php
und die Template Class
dcf/lib/system/style/Template.class.php

Nun möchte ich aber das Smarty entweder darüber ordentlich Included wird oder der Smarty eigene AutoLoader dort wirkt. Google half mir dort leider ebenfalls nicht weiter Smile

Grüße und schonmal Vielen Dank für die Hilfe,
Dennion
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Mon Jan 09, 2017 6:58 am    Post subject: Reply with quote

Hey,

was genau ist denn der Fehler? Du verwendest über deiner Klasse aber schon das "use" oder?

Wenn nein, solltest du dann entweder beim erben

Code:
class Template extends \Smarty


verwenden.

Außerdem wird smarty wahrscheinlich noch gar nicht reingeladen bei dir bzw. deinem Autoloader. Du müsstest Smarty wohl vorher includieren.

Mal abgesehen davon, denke ich, dass es doch einiges im Netz dazu gibt (z. B. Hier).

Ich bin mir auch noch nicht ganz so sicher, warum genau du von smarty erben willst. Meiner Meinung nach ist eine Singleton Smarty Klasse besser, da du dann deine Variablen - die du schon instanziert hast - usw. in jeder Klasse verwenden kannst. Lieber hat dann die Template-Klasse eine Eigenschaft namens "page" oder "smarty" die eben die aktuelle Smarty Instanz darstellt. Aber das musst du natürlich selbst entscheiden
Back to top
View user's profile Send private message Visit poster's website
Dennion
Smarty Rookie


Joined: 09 Jan 2017
Posts: 5

PostPosted: Mon Jan 09, 2017 9:22 am    Post subject: Reply with quote

Hallo Grizzly,

dein Hinweiß mit dem \ vor Smarty hat mir schon geholfen Smile Hatte es vergessen.

Vielen Dank Smile
Back to top
View user's profile Send private message
Dennion
Smarty Rookie


Joined: 09 Jan 2017
Posts: 5

PostPosted: Mon Jan 16, 2017 4:31 pm    Post subject: Reply with quote

Hey,

Aktuell bekomme ich immer den Fehler das er eine Class von Smarty versucht zu Includen die es nicht gibt.

Code:
Smarty_Internal_Compile_Event


Grüße und Danke für die Hilfe,
Dennion
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Tue Jan 17, 2017 6:44 am    Post subject: Reply with quote

Hey,

was genau für ein Fehler wird ausgegeben? Also vollständig. Und seit wann bzw. an welches Codestelle?

Mit deiner aktuellen Aussage kann ich dir erstmal leider nicht wirklich behilflich sein.
Back to top
View user's profile Send private message Visit poster's website
Dennion
Smarty Rookie


Joined: 09 Jan 2017
Posts: 5

PostPosted: Tue Jan 17, 2017 10:06 am    Post subject: Reply with quote

Hey,

obwohl ich Smarty vor meinem Autoloader eingebunden habe mit /Smarty wie du es oben beschrieben hattest. Versucht er über meinen Autoloader die
Code:
Smarty_Internal_Compile_Event
Class zu laden die er bei mir natürlich nicht findet.

Grüße,
Dennion
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Tue Jan 17, 2017 10:29 am    Post subject: Reply with quote

Ich bin mir zwar immer noch nicht ganz sicher ob ich es richtig verstehe, aber vielleicht solltest du in deinem Autoloader folgendes machen

Code:

$fullClassPath = CLASS_PFAD . $fileName;
if(file_exists($fullClassPath)) {
require_once($fullClassPath);
}



der oben aufgeführte Code kommt dann nach der Zeile:

Code:
 $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.class.php';


und ersetzt dann somit die Zeile:


Code:
require CLASS_PFAD . $fileName;
Back to top
View user's profile Send private message Visit poster's website
Dennion
Smarty Rookie


Joined: 09 Jan 2017
Posts: 5

PostPosted: Tue Jan 17, 2017 1:36 pm    Post subject: Reply with quote

Manschmal ... sind es die einfachen dinge im Leben.

Bislang trat der Fehler nicht erneut auf Smile

Vielen Dank
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP