Get SiteConfig variables inside _config.php - php

In SilverStripe 3.4.1 I want to control _config.php file values through the Admin settings. I want to set some variables in Admin > Settings > MyTab and then access these variables in _config.php.
Is there a way to access SiteConfig variables in the _config.php file?
I tried to use several different ways to get the config data:
Config::inst()
print_r/var_dump gives all the values as an array
Config::inst()->get($this->class, 'PropertyName') or $this->config()-> get('PropertyName')
Returns empty
SiteConfig::current_site_config() or any other similar variations based on the previous two
Internal Server Error
The reason I want to do this is I have a plugin that replaces some SilverStripe default action but it requires some data to be inserted. If this data is not inserted it should stay as default.
Here are some resources I have read through to try to find a solution:
http://api.silverstripe.org/3.3/class-Config.html
https://docs.silverstripe.org/en/3.0/topics/configuration/
https://docs.silverstripe.org/en/3.4/developer_guides/configuration/configuration/
https://docs.silverstripe.org/en/3.4/developer_guides/configuration/siteconfig/

The issue is DB::connect is not called at that stage in _config.php. Therefore we cannot retrieve items from the database.
What we can do is call DB::connect in our _config.php before we retrieve our SiteConfig.
Assuming our database config settings are stored in $databaseConfig, here is the code to fetch our SiteConfig:
DB::connect($databaseConfig);
$siteConfig = SiteConfig::current_site_config();
Then we can retrieve SiteConfig variables like so:
$siteConfig->Title;

Related

Magento 2 - how to skip the cache when getting system config value?

I'm trying to get config values using:
$this->_scopeConfig->getValue(
$config_path,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
& it returns the cached value.
Is there any way to make it skip the cache without disabling it?
*I want the cache to be enabled but still bypass it for this value only.
**I also don't want to always clear the cache programmatically before getting it.
-- Any idea?
What you basically need is to query the database directly.
So Inject a Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory in your class.
Then you can query the database :
$collection = $collectionFactory->create();
$collection->addScopeFilter($scope, $scopeId, $section)
The $section is the path,
$scopeId the id of the store or website depending on the scope
& $scope is either "stores" or "website" or "default".

FileMaker - editing container field using php api and Insert from URL script

I am using php api for adding/editing/viewing a FileMaker database. I am using Filemaker pro 14 and FMS 14 in windows environment.
I am having an issue with adding/editing container fields. Tried the solution given in the following link: https://community.filemaker.com/thread/66165
It was success. The FM script is:
Goto Layout[ The layout that shows your container field ]
New Record/Request
Set Variable[$url ; Value:Get(ScriptParameter)]
Insert from URL [Select, No Dialog ; database_name::ContainerField ; $url]
Exit Script
I don't want to add new record. I have several container fields in the layout so it's not a solution to add a record for each one, and I need to be able to modify older records' container fields.
I tried modifying the script as follows:
Go to Layout ["products" (products)]
Go to Record/Request/Page [Last]
Open Record/Request
Set Variable [$url; Value: Get(ScriptParameter)]
Insert from URL [Select, No Dialog; products::brochure; $url]
Exit Script []
note: (Last) parameter is just experimental.
The php script is as follows:
$runscript = $fm->newPerformScriptCommand('products', 'addContainerData', 'http://link_to_uploded_file');
$result = $runscript->execute();
$result returns success, but the file wasn't inserted in the container field.
Somebody pointed to me that to use "Insert from URL" I have to specify a record ID. So I did the follows:
modified the php script to:
$editCommand = $fm->newEditCommand('products', $recordID, $editedData);
$editCommand->setPreCommandScript('addContainerData', 'http://url_to_my_uploaded_file');
$result = $editCommand->execute();
and the FM script (addContainerData) to
Set Variable [$url; Value: Get(ScriptParameter)]
Insert from URL [Select, No Dialog; products::brochure; $url]
Exit Script []
Also the result was success BUT without inserting the file to the container field.
What am I missing? What to do to be able to add container data to new/old records?
A possible workaround is to use PHP functions to encode the file to base 64 and set that value to a text field in FileMaker. Once there, you can have auto enter or a script to take the base 64 value and decode it to a container field. This works well especially for files with smaller file sizes.

Prestashop - Bankwire file difference

Is anyone can explain what is the difference between
payment_return.tpl(path ../bankwire/views/templates/hook/payment_return.tpl)
and
payment_execution.tpl (path ../bankwire/views/templates/front/payment_execution.tpl ) ?
Why in payment_execution.tpl I can see CART/ORDER variables(such as country name, order weight and other) in payment_return.tpl I сan't?
Thanks
These templates work with different "environment":
payment_execution.tpl assigned in /modules/bankwire/controllers/front/payment.php and have access to all template variables assigned in core files.
payment_return.tpl appears in hook and have access to limited list of variables. In file /modules/bankwire/bankwire.php method hookPaymentReturn($params) you may see it, there you have access to $params array and can assign to template any additional variables that you need.

Yii mass assignment from $_GET not working as expected

I'm trying to perform a mass assignment of 2 variables I'm sending via GET to another model::controller (from project::actionCreate to client::actionCreate)
In the _form view for project::actionCreate I've got the following:
<?php echo " ".Chtml::link('+New client',array('client/create',array('Client' => array('redir'=>Yii::app()->controller->route,'redirId'=>$model->id))));?>
With the goal of creating an array "Client" with attributes "redir" and "redirId".
In client::actionCreate I want to do something like
if(isset($_GET['Client']))
{
$model->attributes=$_GET['Client'];
}
Now I noticed that my $_GET var puts client inside subarray 0, so I've tried this with
$_GET[0]['Client']
as well, but no luck. However if I manually assign the variables like this:
$model->redir = $_GET[0]['Client']['redir'];
$model->redirId = $_GET[0]['Client']['redirId'];
Then it works.
Any idea what is up? The goal is to allow someone to create a new client while creating/updating a project record, by sending them to client::actionCreate, but redirecting them back to their original project::actionCreate if they were linked there from my "+New Client" link.
I think the client array is put inside subarray 0 because you've added an array around the parameters. Try removing the array like the following:
<?php
Chtml::link('+New client',array('client/create', 'Client' => array('redir'=>Yii::app()->controller->route,'redirId'=>$model->id)));
?>
I don't know what your model looks like but if the fields aren't assigned they are probably not safe. You can make them safe by adding them to the rules part of your model. Or you could try the following, by specifying the false parameter it will be possible to assign values to unsafe attributes. (http://www.yiiframework.com/doc/api/1.1/CModel#setAttributes-detail)
$model->setAttributes($_GET['Client'], false);
I am not sure creating a link like you want is possible. I have asked something similar some time ago Yii link with [ as a parameter I just could never get the link to how I wanted it. In the end I just created the link the old fashion way, not using CHTML.

Wordpress custom query

I have a wordpress blog. I created a db table which stores dictionary information and I want to publish this data from a URL . (For ex: "myblogaddress.com/mytest.php")
I have been researching for 2 days but nothing works I tried.
In my page; I use the php code shown in blow.
<?php
global $wpdb;
$words = $wpdb->get_results("SELECT * FROM $wpdb->words")
echo $words[0]->ENG;
?>
I wonder that;
- Which directory does my php page to be into ?
- What I need to do (other config, permission etc.) to do what I want.
Regards.
If you're loading it from a standalone PHP file (ie not from within your WordPress theme), you'll have to call wp-load.php to initialise the WordPress variables (including $wpdb). Have a look at this answer, including the comment about only needing wp-load.php.
I'd consider using a relative path (what that would be would depend on where you put your page relative to WordPress) rather than using $_SERVER['DOCUMENT_ROOT'];, but that's just a personal preference.
EDIT
Rereading after seeing your comment, I've just realised $wpdb->words probably won't exist. Try
$words = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "words")
instead. That'll generate the table name correctly as wp_words. Of course, you'll need to populate it the same way.

Categories