I have created CRUD for global configuration parameters. I want to apply this parameters value as main config params (main.php).
I have found some way like add value of these parameters to any .inc file and perform read/write operation. Can anybody help me how can I achieve this? I am beginner in yii.
I have created table structure :
global_config :
Field | Value
pageSize | 20
admin_email| admin#example.com
main.php file as below :
.
.
{
'params' = array(
'pageSize' => 10,
'admin_email' => 'admin#example.com',
);
}
.
.
I am using config file as show above, I want to change it dynamically that it should get value from database.
So that I can make changes in config file from front-end side. I don't need to perform open/write action on main.php
In yii1 you can use params you can set this in main.php
'params'=>array(
'your_param'=>'your_value ',
...
Yii::app()->params['your_param'];
and you can set this value like a simple array poplulating the value form database
$param['yuor_param' =>$your_db_value];
You can't do this for params. As Application parameters are not really meant to be altered and if you change a value, it does not persist across different requests.
These are treated as constant in Yii, So you can't define them after running the script as config files runs at first as your code runs.
Finally, I found solution as per my requirement. I followed given below link from yii forum.
Link : http://www.yiiframework.com/wiki/304/setting-application-parameters-dynamically-in-the-back-end/
Thanks.
Related
I am trying to read/write my configuration in the DokuWiki.
The problem that occurs is when I am trying to call $this->getConf('url'); I always get the response from the conf/default.php file.
This is how my files look like:
admin.php
$url = $this->getConf('url');
conf/default.php
$conf['url'] = 'https://www.example.com';
conf/metadata.php
$meta['url'] = array('string', 'url' => 'https://correct-url.com');
And the value of $url always is:
https://www.example.com
I am not sure what I do wrong.
Thanks!
You may have some misunderstanding to DokuWiki's config system.
The config, which is editable by users, will be saved at /conf/local.php (not inside plugins!). The plugin can only provide a default value at default.php, while the metadata.php is to define how the value is shown on the frontend settings manager.
In your case, the correct URL will be shown, if the DokuWiki global config file (/conf/local.php for example) includes $conf["your_plugin_name"]["url"] = "https://correct-url.com";.
For more: https://www.dokuwiki.org/devel:configuration
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".
we're using codeigniter framework to build application, but we're facing problem to configure '$route' to send correct request.
we just need to setup these route properly.
How i access category:
Category: http://localhost/codeigniter/category/'category-name'/
$route['category/(:any)'] = 'category/index/$1';
Category Post List By Alphabet:
Category Page by List: http://localhost/codeigniter/category/'category-name'/list/'A'/
$route['category/(:any)/lists/(:any)/'] = 'category/lists/$1';
How i access pages:
Page: http://localhost/codeigniter/page/'category-name'/'page-name'/
$route['page/(:any)'] = 'page/index/$1/$2';
we're using rotue something like that, maybe we have problem in it, please check these and let me know how to fix that.
In our codeingiter installation we are using 'codeigniter' dir, 'category' AND 'page' are controllers. in single quotes we are sending values.
Try like
$route['page/(:any)/(:any)'] = 'page/index/$1/$2';
And
$route['category/(:any)/lists/(:any)/'] = 'category/lists/$1/$2';// But Iam not sure
$route['category/(:any)'] = 'category/index/$1';
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.
I am working on cakephp project. I have removed index.php from URL using .htaccess file and now I want to remove view name from URL & add some other two varying parameter. Suppose I choose country & city then these two parameter should appear in URL on selecting them.
The problem I am facing is as cakephp takes
www.example.com/Controllername/viewname
But my requirement is like this
www.example.com/Controllername/param1/param2
If I pass this way It looks for param1 as controller and param2 as view.
Initially should be like:
www.example.com/Controllername/
In your APP/routes.php:
// www.example/com/Controllername
Router::connect('/Controllername',
array('controller'=>'Controllername', 'action'=>'index'));
// www.example.com/Controllername/param1/param2
Router::connect('/Controllername/:param1/:param2',
array('controller'=>'Controllername', 'action'=>'index'),
array('pass' => array('param1', 'param2')));
and your controller:
// set to null/a value to prevent missing parameter errors
public function index($param1=null, $param2=null) {
//echo $param1 . ' and ' . $param2;
}
When generating links:
array('controller'=>'Controllername', 'action'=>'index', 'param1'=>'foo', 'param2'=>'bar');
Order matters. Change paramX to anything you want i.e. country and town
note this does not cover: controllername/param1 - both must be present in this example.
There are other ways to achieve this.
I think you should first make sure that mod-rewrite module is enabled. You shouldn't have had to remove index.php from the url using .htaccess if mod_rewrite were enabled. Check how to enable it in the manual of your webserver and the default .htaccess of cakephp should be able to handle the rest of the routing for you.
After you have enable rewrite module, you can modify the routes as pointed out by #Ross in the previous answer in you APP/routes.php:
// www.example/com/Controllername
Router::connect('/Controllername',
array('controller'=>'Controllername', 'action'=>'index'));
// www.example.com/Controllername/param1/param2
Router::connect('/Controllername/:param1/:param2',
array('controller'=>'Controllername', 'action'=>'index'),
array('pass' => array('param1', 'param2')));