How can one create valid XML files using log4php? The file is not created with valid XML headers. I am using the append option, so I understand I can append to a proper file, but if I want to start a new file I have to make one each time. There must be a proper way to include the XML header if the file is new?
return array(
'appenders' => array(
'default' => array(
'class' => 'LoggerAppenderFile',
'layout' => array(
'class' => 'LoggerLayoutXml',
),
'params' => array(
'file' => $_SERVER['DOCUMENT_ROOT'] . '/logs/log.xml',
'append' => true
),
),
),
'rootLogger' => array(
'appenders' => array('default'),
),
);
This is my config setup.
Related
I would like to validate the file extension only if a file is uploaded.
I have a collection of fieldsets that include a File Input element. If I want to upload a file for only one of the fieldsets and leave the rest of the File Input elements empty the form is not validated, although they have required = false. This validation triggers the "fileExtensionNotFound" error.
Is there a way to add the AllowEmpty to or before the Extension validator?
'file' => array(
'required' => false,
'validators' => array(
array(
'name' => 'Zend\Validator\File\Extension',
'options' => array(
'extension' => array('pdf', 'xls','doc'),
)
)
)
)
I had to specify the type to be FileInput.
'file' => array(
'type' => '\Zend\InputFilter\FileInput',
'allow_empty' => true,
'required' => false,
'validators' => array(
array(
'name' => 'Zend\Validator\File\Extension',
'options' => array(
'extension' => array('pdf', 'xls','doc')
),
),
),
),
We have a boilerplate module that we include on all of your SilverStripe builds. We are attempting to add a new class to our customised WYSIWYG config.
The weird thing is that we have a module dedicated to this but as soon as we move this configuration out of that module and into the new module, the config reflects only a couple of the changes and not all.
Example:
wysiwygboilerplate/_config.php
companyname-boilerplate/_config.php
The first example shows the correct wysiwyg configuration. When that same code is moved to the new location 'companyname-boilerplate/' directory it ceases to function.
This is the snippet of code I am working with. (with the only update being the path to content css)
//-------------------------------------------- WYSIWYG config
$defaultEditorConfig = HtmlEditorConfig::get('cms');
$defaultEditorConfig->setOptions(
array(
'theme' => 'advanced',
'priority' => 1,
'browser_spellcheck' => true,
'body_class' => 'wysiwyg',
'content_css' => '/companyname-boilerplate/styles/wysiwyg.css',
'schema' => 'html5',
'extended_valid_elements' => 'figure,figcaption',
'end_container_on_empty_block' => true,
'style_formats' => array(
array(
'title' => 'H1',
'block' => 'h1'
),
array(
'title' => 'H2',
'block' => 'h2'
),
array(
'title' => 'H3',
'block' => 'h3'
),
array(
'title' => 'H4',
'block' => 'h4'
),
array(
'title' => 'H5',
'block' => 'h5'
),
array(
'title' => 'Paragraph',
'block' => 'p'
),
array(
'title' => 'Blockquote',
'block' => 'blockquote',
'wrapper' => true
),
array(
'title' => 'Figure',
'block' => 'figure',
'wrapper' => true
),
array(
'title' => 'Figure caption',
'block' => 'figcaption',
'wrapper' => true
)
)
)
);
$defaultEditorConfig->disablePlugins('contextmenu');
$defaultEditorConfig->enablePlugins('lists', 'paste');
$defaultEditorConfig->setButtonsForLine(1, 'styleselect, formatselect, separator, bold, italic, separator, justifyleft, justifycenter, justifyright, separator, bullist, numlist, separator, charmap, ssmedia, separator, sslink, unlink, separator, code');
$defaultEditorConfig->setButtonsForLine(2);
$defaultEditorConfig->setButtonsForLine(3);
My initial thoughts are that this is to do with the order SilverStripe is loading the configuration files, but there are no other files / modules that define a HtmlEditorConfig that I am aware of.
The other thought I had was around caching, I cleared out the SilverStripe cache, my browser cache and even ran a dev/build with still no joy, so that rules out caching
As the modules config are included in alphabetical order you either have to rename your boilerplate module (or the installation dir in composer.json) that it comes after framework or put the config inside mysite manually, cause mysite is added at last and there you can overwrite settings.
Yii version 1.1.8
I have added a column to a table in a mysql database,
but the new column is not showing in output of $model->getAttributes() method call
I deleted all files in protected/runtime folder, but still no column
config: 'schemaCachingDuration' => 0, // in seconds. <1 means off
I can add data to the new column directly in the database.
Are there any other things that I can do to debug this?
index.php
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following line when in production mode
//debug
defined('YII_DEBUG') or define('YII_DEBUG',true );
//show profiler
defined('YII_DEBUG_SHOW_PROFILER') or define('YII_DEBUG_SHOW_PROFILER',true);
//enable profiling
defined('YII_DEBUG_PROFILING') or define('YII_DEBUG_PROFILING',true);
//trace level
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
//execution time
defined('YII_DEBUG_DISPLAY_TIME') or define('YII_DEBUG_DISPLAY_TIME',false);
require_once($yii);
Yii::createWebApplication($config)->run();
main.php
<?php
return CMap::mergeArray(array(
'timeZone'=>'UTC',
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'catchAllRequest' => null, // null if online, array('site/offline') if offline,
'sourceLanguage' => 'en_ca',
'theme' => 'td',
'charset' => 'UTF-8',
'preload' => array('log'),
'import' => array(
'application.models.*',
'application.components.*',
'application.extensions.*'
),
'modules' => array(
),
// application components
'components' => array(
'format' => array(
),
'user' => array(
// enable cookie-based authentication
'allowAutoLogin' => true,
'autoRenewCookie' => true,
),
'widgetFactory' => array(
'enableSkin' => true,
),
'urlManager' => array(
),
),
'db' => array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=mydb',
'emulatePrepare' => true,
'initSQLs'=>array("set time_zone='+00:00'"),
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
'enableParamLogging' => true, //show parameter values in log
// 'schemaCachingDuration' => 0, // in seconds. <1 means off
'enableProfiling' => YII_DEBUG_PROFILING, //show sql profile info in log
'nullConversion' => true,
//'initSQLs'=>array('set time_zone="+00:00"')
),
'errorHandler' => array(
),
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'CFileLogRoute',
'levels' => 'error, warning',
'filter' => 'CLogFilter',
'enabled' => !YII_DEBUG
),
array(
'class' => 'CPhpMailerLogRoute',
'levels' => 'error',
'emails' => 'neilmcguigan+tderror#gmail.com',
'filter' => 'CLogFilter',
'enabled' => false,
),
array(
'class' => 'CWebLogRoute', // show log messages on web pages
'enabled' => YII_DEBUG,
'filter' => 'CLogFilter',
//'showInFireBug' => false
),
array(
'class' => 'CProfileLogRoute',
'enabled' => YII_DEBUG,
'showInFireBug' => false
)
),
),
'request' => array(
),
'securityManager'=>array(
)
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params' => array(
),
), require(dirname( __FILE__ ) . '/override.php'));
Having just went through this problem -- I found out the new field names need to be in the attributeLabels function in the model
public function attributeLabels()
{
return array(
'id' => 'ID',
'newfield' => 'New Field',
...
Be careful with using the "better still update overwrite your whole model" suggestion if you are like me and have a lot of custom code in your models. As Sankalp Singha suggests, Just copy the "diff" (green part) from using gii and add the part from attributeLabels to your code.
After you have added a new column in your table then just go to Gii and then click on model generator. In that put the name of your table again and then click preview. There would be an option of diff click on that and then copy the highlighted green code and copy paste it in your original modal or better still update overwrite your whole modal. Then check if you are able to get the values inside and are able to get the attributes. This should work.
Running into a bit of a hurdle, and I can't find any supporting documentation. My use case is fairly simple. The Application module has javascript that should go into the head, and one of my other modules, Foo also has script that should go into the head. I assumed that this Assetic module could solve that. Here's what I inferred:
Application Config
/**
* Assetic
*/
'assetic_configuration' => array(
'buildOnRequest' => true,
'cacheEnabled' => false,
'webPath' => realpath('public/assets'),
'basePath' => 'assets',
'default' => array(
'assets' => array(
'#base_css',
'#head_js',
),
'options' => array(
'mixin' => true,
),
),
'modules' => array(
'application' => array(
# module root path for yout css and js files
'root_path' => __DIR__ . '/../assets',
# collection of assets
'collections' => array(
'base_css' => array(
'assets' => array(
'css/*.css',
),
'filters' => array(),
'options' => array(),
),
'head_js' => array(
'assets' => array(
'js/*.js',
),
'filters' => array(),
),
'base_images' => array(
'assets'=> array(
'images/*.png',
),
'options' => array(
'move_raw' => true,
)
),
),
),
),
),
and then in my Foo module...
Foo Module config
/**
* Assetic
*/
'assetic_configuration' => array(
'default' => array(
'assets' => array(
'#base_css',
'#head_js',
),
'options' => array(
'mixin' => true,
),
),
'modules' => array(
'foo' => array(
# module root path for yout css and js files
'root_path' => __DIR__ . '/../assets',
# collection of assets
'collections' => array(
'base_css' => array(
'assets' => array(
'css/*.css'
),
'filters' => array(),
'options' => array(),
),
'head_js' => array(
'assets' => array(
'js/*.js' // relative to 'root_path'
),
'filters' => array(),
'options' => array(),
),
'base_images' => array(
'assets'=> array(
'images/*.png'
),
'options' => array(
'move_raw' => true,
)
),
),
),
),
),
With this config, unfortunately, only the Foo module's javascript makes its way into head_js.js. I'm feeling like that meme with Milton in it, going "I was told there would be asset combining!" :)
Any help you could offer, is appreciated.
Thanks!
Ok - I've figured it out. Hopefully this helps someone else one day. The configuration keys I noted above weren't inaccurate -- but -- they weren't crafted properly when a secret undocumented feature is considered; had to crack the source open to learn that including the word 'head' in an asset bundle actually autoloads it in the head. It's a nice feature in the end, but really a head scratcher when you're not aware of it.
I'm having problems implementing the IsImage File validator in a Form class in Zend Framework 2-beta5.
In general I'm having problems using any File validator in a Zend Form class in Zend framework 2.
I couldn't find any relevant documentation.
I found that for example Float validator that resides at Library/Zend/Validator
can be used with the following code:
$this->setInputFilter($inputFactory->createInputFilter(array(
'alcohol_vol' => array(
'name' => 'alcohol_vol',
'required' => true,
'validators' => array(
array(
'name' => 'Float',
),
),
),
)));
the IsImage file validator resides at /Library/Zend/Validator/File and can't find a way to use it. any information regarding the issue would be greatly appreciated.
thanks!
Kfir
Try to add this snippet under validators key, like this:
'validators' => array(
array(
'name' => '\Zend\Validator\File\IsImage',
'options' => array(
'break_chain_on_failure' => true,
),
),
),
But sometimes, depends on server configuration, IsImage might not working. Then use Extension validator instead:
'validators' => array(
array(
'name' => '\Zend\Validator\File\Extension',
'options' => array(
'extension' => array(
'png', 'jpeg', 'jpg',
),
'break_chain_on_failure' => true,
),
),
),
Upload file validate/filter should use Zend\File\Transfer but not Zend\Form
Try below way to add file validator
$fileTransfer = new Zend\File\Transfer\Transfer();
$fileTransfer->addValidators(array(
array('IsImage', true)
));
if($fileTransfer->isValid()){
$fileTransfer->receive();
}