so, I have some php files in my apps/myprogram/lib folder. e.g. apps/myprogram/lib/myLibA.class.php
When I run in my modules/actions/ scripts, and try to use the functions in myLibA, I cannot. because symfony complains that the myLibA class is not defined.
do I need to specify anywhere in the symfony framework that myLibA.class.php is a required library?
Symfony's autoloader looks by default for your classes in the top-level <project>/lib directory. Any file in that directory or below (with the exception of "vendor") will be searched for classes. Symfony searches for any .php file with class declarations and adds them to the autoload system.
Additionally, you can add search paths in your application's autoload.yml file. For example, for one of my applications I've put a third-party Flickr library in <project>/vendor/phpFlickr, and my <project>/apps/frontend/config/autoload.yml file looks like:
autoload:
vendor_php_flickr:
path: %SF_LIB_DIR%/vendor/phpFlickr
recursive: on
That allows all classes below .../vendor/phpFlickr to be autoloaded.
this is an alternative way, you can define/add to your preExecute this:
public function preExecute()
{
$this->getContext()->getConfiguration()->loadHelpers('Foo', 'Bar');
}
taken from (http://oldforum.symfony-project.org/index.php/m/92916/)
Related
I'm trying to read in the text (as a string) of an XML file from my Resources. The XML file is named MyXMLResourceFile.resx.
I tried using the C# way using
let myFile : string = Properties.Resources.MyXMLResourceFile
but it is giving me the error (under Properties):
The namespace or module 'Properties' is not defined.
I'm assuming I'm missing an open but have no idea what it would be.
Sorry, I'm still pretty new to F# coming from VB.
Additional information:
I made the resx file myself per this SO answer I then looked to see how others accessed it. In C# they did Properties.Resources.XXXX per this project I saw you could use ResourceManager but didn't see any method to read the whole file directly into a string.
The namespace or module 'Properties' is not defined.
That's because the namespace Properties is not defined. You probably brought the resx file from another project. Open the associated .Designer file, if it doesn't appear in the F# project, open it up in the original project. You will see a namespace with and a bunch of C# code, assuming the original project was in C#. The namespace of this file has to be the same namespace of the project where you are trying to call it.
But, since this is C# code, it won't run on a F# project. You have two choices: use a code generator to generate the associated .Designer class in F# code with the Properties namespace, (I don't know if such generator exists); or pre-compile the resx in the original project and reference it as a dll from your F# project, then you can access it with ResourceManager.
I'm using JSFL to writing some script, I need parse json string from some config files, so I need the JSFL can parse json string, but JSFL seems can't do this. then I thinks to include some json lib, like json.js, to JSFL file.
Way can I include the json.js file to my JSFL file?
Sorry for my english.
The absolute bare minimum would be:
// #include Config._jsfl
var scriptPath = FLfile.uriToPlatformPath(fl.scriptURI);
var scriptPathEnd = scriptPath.lastIndexOf("\\");
scriptPath = scriptPath.slice(0, scriptPathEnd + 1);
fl.runScript(FLfile.platformPathToURI(scriptPath + "Config._jsfl")); /*jsl:import Config._jsfl*/
This is more or less copied from my code, JSL tags included. I make the extensions on any libraries to be ._jsfl so that if it's in Flash's Commands folder, they don't show up in the menu.
I wrote a set of static classes (a Logging system, URI conversions, array utility functions) and wrote a global include function using them to automatically convert a relative path to an absolute URI based upon the running scripts location so that I could just say include("file._jsfl"); to simplify my scripts. HOWEVER all my scripts have to do that first include as shown above to gain the include function. Since my include function relies on a handful of static classes, I've not pasted it here.
Edit: spelling error.
If the library is local, you can store it in a subfolder of your Flash config path, i.e.
C:\Users\username\AppData\Local\Adobe\Flash CS6\language\Configuration\jslibs
Then, it is quite easy to include it in a single line:
fl.runScript(fl.configURI + "jslibs/file.js");
In my standard Symfony2-app I'm having a bunch of bundles with some entities. Some of these entities are not located in the standard folder the automapping of doctrine finds out (e.g. /src/Acme/DemoBundle/Entities) but in a different location.
I could easily use config.yml to tell doctrine to use a different location like this:
doctrine:
orm:
auto_mapping: false
mappings:
AcmeDemoBundle:
type: annotation
prefix: Acme\DemoBundle\Entities\
dir: %kernel.cache_dir%\Acme\DemoBundle\Entities
This works. But say I'm having 10 bundles with a different mapping the config.yml gets bloated very fast. Is there another way, e.g. with a CompilerPass or via DependencyInjection, so I don't need to add all entities in my config.yml? I already looked into the DoctrineBundle, but had no luck so far.
To answer myself:
the most simple way is to adjust the autoloading, there is no need to modify the settings. In Symfony's standard distribution in autoload.php you have to add another location to the registerNamespace-method:
$loader->registerNamespaces(array(
[...]
'Foo' => array(__DIR__.'/../src/dirA', __DIR__.'/../src/dirB')
));
Doctrine will then look for entities in the "Foo" namespace first in dirA and then in dirB if not found.
You can include other configuration files using imports
# yaml
imports:
- { resource: entities.yml }
<!-- xml -->
<imports>
<import resource="enditites.xml" />
</imports>
// PHP
$loader->import('entities.php');
You don't even have to stick to a single file type. It's possible to import an xml configuration file to a yaml file, for example.
What is the best way to put custom library or helper methods in symfony?
I am using doctrine with my project. One place I consider to put is under project_root/lib/vendor/MyClasses/
But if I want to create a class or helper function which will use some core symfony/doctrine methods and return a result then how to do that and where should I put it?
I want it to call from different modules to avoid code duplication.
As for the custom library part of the question, you might probably want to put your external library into the lib/vendor folder. Since symfony doesn't automatically load everything that's in there, you'll have to tell its autoloader to do so.
You can either extend your config/ProjectConfiguration.class.php (as described here) or (and this is the much simpler and cleaner way) you add them to your config/autoload.yml (you might have to create this one).
For the latter option, this is a great place to start looking at.
It seems to be a duplicate question.
As asked in symfony's 1.2 "Definitive Guide" docs :
Helper functions (regular PHP functions returning HTML code) should be saved in a file called FooBarHelper.php, where FooBar is the name of the helper group. Store the file in the apps/myapp/lib/helper/ directory (or in any helper/ directory created under one of the lib/ folders of your project) so it can be found automatically by the use_helper('FooBar') helper for inclusion.
So, if you want to create custom helper FooBar for foo() function, create file lib/helper/FooBarHelper.php :
function foo() {echo "foo!"; }
to use it in your template:
use_helper('FooBar')
....
foo(); //outs "foo!"
I use symfony's ProjectConfiguration.class.php for configuring doctrine's connection:
public function configureDoctrineConnectionCertby(Doctrine_Connection $conn)
{
$conn->setListener(new MyListner());
}
Where should I define MyListner class within a symfony project?
You should make a lib/Doctrine (or lib/doctrine/Doctrine - this is what Symfony does inside of sfDoctrineGuardPlugin) folder for all Doctrine files. Since Listeners are Doctrine files not Symfony files, you should be following Doctrine naming conventions for them. In this case, MyListener would go in:
/lib/Doctrine/Record/Listener/MyListener.php
This is the "proper" way to do this. It would of course work if you simply threw the files in /lib or /lib/Doctrine.
If you want your listener to be available at the project level, put it in the /project/lib/ folder. If you just want it to be available at the module level, put it in the /project/apps/module/lib/ folder.