Ask your Symfony questions! Pay money and get answers fast! (more info)

Why won't my classes autoload? Symfony

  • SOLVED

I'm trying to override the whole Symfony template system, so I'm copying some of the core files to my local lib files. I'm overriding these 3 files:

/usr/share/php/symfony/view/sfView.class.php

/usr/share/php/symfony/view/sfPHPView.class.php

/usr/share/php/symfony/view/sfPartialView.class.php

I've copied them to the top level lib/ folder in my project. Then I run:

symfony cc

And yet, none of my changes seem to show up. Do these classes not get auto-loaded? How do I override them?

Right now, in my local copy of sfView.class.php, I have a "hello":

public function __construct($context, $moduleName, $actionName, $viewName)
{
echo "hello";
$this->initialize($context, $moduleName, $actionName, $viewName);
}


This never shows up on any page, which I think is impossible.

I run "symfony cc" between every change, yet no changes appear.

How to I get Symfony to see my local copies of these core files?


I am using version 1.2.5

[UPDATE]

Where are the yaml files for the core of Symfony? I can not find them. I tried this:

/usr/share/php/symfony$ ls -R | grep -i *yaml
yaml
sfSimpleYamlConfigHandler.class.php
sfYamlConfigHandler.class.php
sfI18nYamlExtractor.class.php
sfI18nYamlGeneratorExtractor.class.php
sfI18nYamlValidateExtractor.class.php
YamlSf
YamlSf.php
YamlNode.php
./plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Parser/YamlSf:
GenerateModelsYaml.php
GenerateYamlDb.php
GenerateYamlModels.php
./yaml:
sfYaml.class.php
sfYamlDumper.class.php
sfYamlInline.class.php
sfYamlParser.class.php


In version 1.0 of Symfony, the yaml files were in the core Symfony folder. Is this stuff hard coded now or what?

This comes back empty:

/usr/share/php/symfony$ ls -R | grep -i *yml

Answers (2)

2010-11-24

Gert Findel answers:

Can you override this files in you app's lib folder?
If this doesnt work, I believe you can extend them and then use the extended class using de yml configuration.

http://snippets.symfony-project.org/snippet/115

What are you trying to do? Maybe you are trying to code the wrong solution.


Gert Findel comments:

Look that the different Files you want to extend have instructions like

$this->dispatcher->notify(new sfEvent($this, 'view.configure_format', array('format' => $format, 'response' => $context->getResponse(), 'request' => $context->getRequest())));

maybe you could just add listeners to the events


Gert Findel comments:

If its autoloaded with the core you could use the core_compile yml file

frontend/config/core_compile.yml


- %SF_ROOT_DIR%/lib/myClass1.class.php
- %SF_ROOT_DIR%/lib/myClass2.class.php
...


so its compiled with the core, but after the original classes


for details http://www.symfony-project.org/gentle-introduction/1_4/en/18-Performance#chapter_18_sub_core_compilation


Lawrence Krubner comments:

Gert, I appreciate your reply, but you are linking to a snippet from 2006. Possibly it is out of date? I tried to follow its advice, but I get a 500 error and this stack trace:

500 | Internal Server Error | sfException
Call to undefined method tmaView::getContext.

stack trace
at ()
in SF_SYMFONY_LIB_DIR/view/sfView.class.php line 583 ...
$event = $this->dispatcher->notifyUntil(new sfEvent($this, 'view.method_not_found', array('method' => $method, 'arguments' => $arguments)));

if (!$event->isProcessed())

{

throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));

}


return $event->getReturnValue();
at sfView->__call('getContext', array())
in n/a line n/a ...
at tmaView->getContext()
in SF_ROOT_DIR/apps/contest/lib/tmaView.php line 10 ...
at tmaView->configure()
in SF_SYMFONY_LIB_DIR/view/sfView.class.php line 144 ...
at sfView->initialize(object('sfContext'), 'question', 'show', 'Success')
in SF_SYMFONY_LIB_DIR/view/sfView.class.php line 93 ...
at sfView->__construct(object('sfContext'), 'question', 'show', 'Success')
in SF_SYMFONY_LIB_DIR/controller/sfController.class.php line 376 ...
at sfController->getView('question', 'show', 'Success')
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 138 ...
at sfExecutionFilter->executeView('question', 'show', 'Success', array(object('Question'), 'howManyAnswers' => '6', object('sfPropelPager'), 'explanationWhyTheViewerCanNotPostAnAnswer' => '', 'averageEstimate' => '35', array(object('Discourse')), array()))
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 114 ...
at sfExecutionFilter->handleView(object('sfFilterChain'), object('questionActions'), 'Success')
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 47 ...
at sfExecutionFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR/filter/sfCommonFilter.class.php line 29 ...
at sfCommonFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...


Gert Findel comments:

Look for the core_compile file

/usr/share/php/symfony$ ls -R | grep -i core_compile


Gert Findel comments:

for the sfPHPView.class.php:
you should just extend it and use the factories.yml file to configure it with>

view:
class: myView

for the others I would try the core_compile.yml approach (as I mentioned before)


Lawrence Krubner comments:

Okay, I got a highly modified version of that snippet from 2006 to work for version 1.2.5. But what is this exactly:


all:
view_class: tma


I use that in app/config in a file called module.yml to override sfPHPView.class.php. But how do I override sfView? I'm having a hard time finding out where these yaml settings are documented.


Gert Findel comments:

I am not sure if that works but I would try to copy/paste the file in your projects lib folder and then

open or create
%SF_ROOT_DIR%/apps/<your_app>/config/core_compile.yml

and type this inside


- %SF_ROOT_DIR%/lib/myClass1.class.php
- %SF_ROOT_DIR%/lib/myClass2.class.php
...


Gert Findel comments:

open or create
%SF_ROOT_DIR%/apps/<your_app>/config/core_compile.yml

and type this inside



- %SF_ROOT_DIR%/lib/sfView.class.php
- %SF_ROOT_DIR%/lib/sfPartialView.class.php
...

2010-11-25

Christian Schaefer answers:

The short answer is: You simply can not do that.
The longer answer is this:
The symfony core classes are not auto loaded like all the others. Instead there is a special core autoloader which is started second thing after including the project configuration class (look in the top of that file). Just before it starts the symfony lib dir is manually set. This is the place where the core autoloader expects the symfony classes.
All classes found will be put in a class name to filepath list in your cache dir.
Loading of your lib folders happens afterwards; too late for overloading. Worst case would be clashes of class names..

What you have to do instead is extend these classes and set them in your factories.yml.
I haven't done this but I suggest you take a look into the sfSmartyPlugin which apparently does the same thing.


Lawrence Krubner comments:

Do you know the key for setting the view file in factories.yml? There is no obvious key for this in my factories.yml file, in version 1.2.5