I have a few of my own constants in symfony, and I need to make them available throughout the application, where to best define them?
I tried, in the directory myapps\config\config.php, define my constant in this way:
sfConfig::set('aaa', 'mya');
But when I tried to access the constant in myapps\apps\frontend\modules\login\actions\actions.class.php, using this comand
sfConfig::get('aaa')
I simply get a null, indicating that it hasn't been defined.
How and where to define symfony constant so that it is accessible throughout the whole project?
This is how I solved the problem:
Put the following into my myapp/apps/frontend/config/app.yml:
all:
.app_set:
bpobackend: me
bpoRedirectScreen: allow
Then in action module, call the var_dump to check the value
var_dump(sfConfig::get('app_bpobackend'));
looks like you are trying to use symfony 1.0 style configuration with symfony 1.1 or 1.2. all config.php files have been removed in 1.1. see Overview of the Configuration Files for what to use instead. and always be sure to look at the documentation for the proper version (1_2 (or whatever version you are using) in the url).
I have tried to add constant in the config.php in Symfony 1.0..
So If you want to add constant variables in config.php then
sfConfig::add(array('SF_DEFAULT_DATEFORMAT' => 'dd-MM-yyyy'));
This is the code where I have define the date format with name 'SF_DEFAULT_DATEFORMAT'...
So You can Tried with this One ...
Related
I am busy making a sublime text plugin/package that will ease development of lua scripts in my workplace.
We have several lua files with different extensions depending on their purpose. I want ST3 to give the proper lua syntax to these files.
I know you can set ST3 to remember syntax for a specific file extension and this is saved as a (in my case) Lua.sublime-settings file in AppData\Roaming\Sublime Text 3\Packages\User
However, if I put this file in my new plugin's folder, it's ignored.
Am I doing something wrong or is what I want not possible?
This doesn't work because syntax specific settings are only loaded from the package that defines the syntax and from the User package (so the user can customize them).
The following is a quote from the official documentation on settings:
Settings files are consulted in this order:
1. Packages/Default/Preferences.sublime-settings
2. Packages/Default/Preferences (<platform>).sublime-settings
3. Packages/User/Preferences.sublime-settings
4. <Project Settings>
5. Packages/<syntax>/<syntax>.sublime-settings
6. Packages/User/<syntax>.sublime-settings
7. <Buffer Specific Settings>
The only places where <syntax> is referenced is from the package itself and from the user package.
If I had to guess, I would say that this is because outside of the original package author that defined the syntax, all other settings would be considered user customizations, and those settings need to be in the User package (specifically in the root of it) to ensure that they're loaded last.
A simple (but undesirable) solution would be to document for the user that they have to take this step manually.
Another approach would be to add some plugin code that extends the settings when your plugin is loaded:
def plugin_loaded():
settings = sublime.load_settings("Lua.sublime-settings")
extensions = settings.get("extensions", [])
if "blarb" not in extensions:
extensions.append("blarb")
settings.set("extensions", extensions)
sublime.save_settings("Lua.sublime-settings")
If you go this route you may want to include an extra sentinel setting somewhere (in settings specific to your package or some such) that says if you did this or not instead of just forcing the setting in as the example above does.
In practice you would then check if you've set that sentinel or not instead of forcing the extension in, so that if the user decides to use some other syntax for your files you're not forcing them into the Lua syntax.
It's also possible to define your own syntax that just embeds the standard Lua syntax, which allows this to Just Work⢠without having to write any code or have the user do anything:
%YAML 1.2
---
name: Blarb
scope: source.lua
file_extensions:
- blarb
contexts:
main:
- include: scope:source.lua
When you do this, the scope in the file will still be source.lua because that's what the scope in the syntax file says. and the status line will set the syntax name to Blarb. You could modify either of those to change the top level scope or displayed name, if desired.
An example would be to change the scope to source.blarb so that you could create key bindings/snippets that only apply to Lua files of your specific variant.
A potential downside/feature of this is that since the name of the syntax specific settings comes from the name of the file that provides the syntax, if the user has any Lua specific settings, they won't apply to your Blarb files by default.
Similarly anything that's specific to Lua by checking for a scope of source.lua won't work in Blarb files for same reasons, which may or may not be an issue.
I am developing an app using Angular 2 and Ionic. I am using a bluetooth library for Cordova, so not writing using ES6-modules and exports.
The library defines a global variable called 'bluetoothle', and it works as expected when I run it. However, I get a lot of complaints from the typescript compiler. I would like to either:
(Preferred) Have some better way to import the ES5-library to my typescript-project.
Tell the compiler to ignore this error.
Declare the variable, and then let the library assign value to it(however, I don't know how to declare globals in typescript the way it was possible in ES6.
Thanks in advance,
Markus
You have two options there which depend on how much work you want to put in them.
The first and easy option is to just declare the variable at the top. This will tell TypeScript that this is a variable of type any and that it doesn't need to care about where it came from or which members it has:
declare var bluetoothle;
The other route, which would be cleaner but is way more work is writing a type definition file.
I have tried using creating a different module and attaching the ZfcUser\Form\Register over init method. But it wasn't working.
I want to add few custom fields, with changing any thing in the vendor dir, as is it not a good practice. I also tried using user_entity_class ,creating a custom 'User' class, but it was creating some route issue in other modules, with zfc-user , I'm also using zfc-admin and zfc-adminuser, the error was coming in zfc-adminuser, Couldn't found the class was the error.
Thanks in advance.
Well there are some issue regarding the overriding of the module ZFC-User, But still you can overwrite it manually.
One way I have used is a bit old fashioned but working. What I have done is I have copied complete module the to module folder. Then pointing the form towards to my module where the changes are required, rest all are pointed to default.With this you can update your module. Make sure you point the user_entity_class to your module something like this:
'user_entity_class' => 'MyZfcUser\Entity\User',
you can find this in config\autoload\zfcuser.global.php
I have a file that represents all components of a game. I want to load the file into cache on boot, then have the ability to call the attributes of the file from the controllers. How do I begin?
I like http://cobravsmongoose.rubyforge.org for most simple XML handling:
CobraVsMongoose.xml_to_hash(File.open('path/to/xml').gets)
As for your specific case, I would add an initializer which requires cvm and sets the value above to a constant, which you could then access wherever you want...
# config/initializers/load_xml.rb
require 'cobravsmongoose'
MY_XML = CobraVsMongoose.xml_to_hash(File.open('path/to/xml').gets)
Try out REXML, its an XML parsing library for Ruby. I think it comes with the standard version of Ruby, so you shouldn't even need to install a gem.
In a tutorial on setting up internationalization and localization, "Kohana 2.4 I18N (internationalization and localization) Library" the author says:
I'd put it in a Base Controller so that all Controllers inherit it.
This is the code:
I18n::set_locale('tl_PH');
I tried placing it in all the controller and places I could but is not working.
Where is the exact place in Kohana 3.0.4.2 that I should place it?
Put this line in bootstrap.php:
I18n::lang('tl-PH');
The I18n::set_locale function doesn't exist in Kohana 3. See I18n class docs.
Not sure who wrote that article, but locale should be set using the config locale.php config file. You may have to copy it from system/config/locale.php into your application/config/locale.php and set the proper values.
Calling I18n::set_locale() should only happen if you need to change from the default (set in locale.php) to something different (like Dutch, English, etc...).
P.S I'm a Kohana 2.4 core dev...
If you want to set the PHP locale, you will change this is in application/bootstrap.php, there is a setlocale(LC_ALL, 'en_US.utf-8') line there already which you can change to the correct language.
To set Kohana's internal language for translation, add a call to I18n::lang('en-us') (replace "en-us" with your language) after the Kohana::init() call, before Route::set().