I have a custom contenttype called posts, which has about ten records. Each of them is stored in bolt_posts table together with other Bolt-specific tables. I'd like to access a post with id = 1 in one of my custom php files. The problem is that the database for my application is separated from the database which holds internal Bolt tables. Is there a native Bolt API that I could use in order to query those tables? I've found this https://docs.bolt.cm/3.1/extensions/storage/queries, but I am not sure what directives I need to put in my php code in order to be able to run such commands. Thanks in advance!
Assuming you're using composer to load Bolt into an existing application then this can be achieved by constructing an instance of a Bolt app.
All you need is a configuration, that takes the root folder of the Bolt site and then to initialize the app. For instance, assuming Bolt is accessible via autoload..
$config = new Bolt\Configuration\Composer('/path/to/bolt/root/');
$app = new Bolt\Application(['resources' => $config]);
$app->initialize();
That gets you the instance of a Bolt app and then you can follow the instructions in that documentation to query the Bolt db.
eg:
$record = $app['query']->getContent('pages/1');
if you want to access the content from within an external application, you need to connect to the bolt database manually and fetch the data. Bolt's own storage layer can only be used when you work directly in Bolt (e.g. within an extension).
Related
I am beginner in DNN. I am creating a module which provides Login, Dashboard and Add-Update Form. I have data in JSON format. I want to store it temparory while user use the website. Data will be destroy as soon as user will close the website.
Currently I have created a folder in my Solution Explorer of project in Visual Basic and created 3 .json files which stores login_info.json, basic_info.json and auth_info.json. I write json data whenever user login and I make it blank when user logout.
Above method is working fine now but I afraid it will work when I will publish this module.
Also I may have situation where I need to store image some where. I don't know how I will manage.
Can anybody please guide me?
Is this proper way to store data temparory in DNN?
Is there any other better way?
After getting one of reply for Database Suggestion
Is there any table which same as User Meta in DotnetNuke?
You use the ConnectionString that is used by DNN and access the database as you would normally.
DotNetNuke.Common.Utilities.Config.GetConnectionString()
Or you can use the Data Access Layer that the DNN Framework supplies. For that take the Christoc Templates. In there is all you need to communicate with the DB.
My site is preparing to go live. As updations are developed on my site, I would like to test the updations in real server without affecting the real data. I need 2 databases(the same database with 2 names) to connect my site at the same time. One for testing myself and other for the real users.
I tried duplicating the config/main to config/main_test and the main index.php to index_test.php. And implemented 2 database connections in config/main.php and config/main_test.php. And connected those files to the index.php and index_test.php and tried to run the site with http://mysite.com/index.php and http://mysite.com/index_test.php. But both urls are working based on the database connection provided in config/main.php.
How can I get use the 2 databases? I dont think keeping 2 copies of the entire site is a good idea. All suggestions are welcome
You can implement it with duplicating your config file main.php to main-test.php and index.php to index-test.php. In the main-test.php file set the new DB connection properties. In index-test.php change the path to configuration and you can also enable the debug. Here is an example of your index-test.php:
$yii = '/opt/yii/framework/yii.php';
$config = dirname(__FILE__) . '/protected/config/main-test.php';
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
require_once($yii);
Yii::createWebApplication($config)->run();
And don't forget to use the URL with index-test.php in it.
define an environment variable that's set equal to 'DEVELOPMENT' or 'PRODUCTION'
define('ENVIRONMENT', 'DEVELOPMENT');
Then your database connection can be based off that constant.
if(ENVIRONMENT == 'DEVELOPMENT'){
//connect to development database
}
You can switch that to 'PRODUCTION' when you want the site to be working in production mode.
You shouldn't be doing testing on a production machine though.
I would like to test the updations in real server without affecting the real data
You can't actually. Far better to use a copy of your live data on a staging environment to make sure things work. If your code expects new DB fields and your DB doesn't have it, you are going to have problems.
Better to have migrations making changes to non live data while you check things.
I have the following problem:
I Am using a Django framework.
One of the parts in a system (non-django) writes to the database, in the same database that django is using.
I want to have a signal when an object is being saved. It's a django model object but not saved via django, but directly in the mysql database.
Is there a way django can watch save-actions in his database when it's not being saved by django?
The neatest way would be: create an Api, and let the save action run through this api. The save signal can than be django default. (but this depends on some work of externals... so not the prefered route... for future development it sure is).
Another option is to implement celery and create a task that frequently looks whether one of the saved objects has had no follow up..... (also quit some puzzling I guess to get this up and running)
But there might be an easier... for me unknown?
I saw django watchdog solutions for file systems... not for databases (probably because django has this build in... when properly done through django)
to complex it: I test and develop locally with sqlite .... but the save signal I can put in my tests without needing to get this locally working.... as long as it works in mysql, I Am happy.
You can try this solution:
Create a new table 'django_watch' with one column 'object_id' (add other columns like 'created_datetime' etc according to your standards);
Lets say your main table is 'object'. Add a mysql trigger for the INSERT event on this table.
You should add an extra insert query inside the trigger to insert the object_id into 'django_watch' table.
Now you can have a cronjob that will be inpecting the new table 'django_watch' (for updations in Django objects) and perform necessary actions. You can run this cronjob continuously with some 1 minute delay (upto you).
In the end, I wrote an api that can be called by the thirdparty module. I delivered the code to logon on django using c-code to this api and call the GET of this api. (using django rest framework). This api just saves the object (the id given in the url), and from there on it's default django. The only thing the third party had to do is build in my code to call the api as well....
Maybe not the best solution, but the best to implement for my problem....
My current project is about doing some changes in an already build web application (PHP/MySQL). For displaying data, the previous developer used views. I got the app on my computer in order to get familiar with it and I can't seem to make those views work (I don't get any output in the app).
I searched the web for this an there seems to be a problem when you create a view with one database user and the that user no longer exists.
Anyone who got into this issue before? How can this be solved?
If you're importing the views from SQL dump file, they are probably defined like this
CREATE DEFINER = 'userWhoDoesNotExist#thisServer' VIEW viewName AS ....
Try removing the DEFINER = part, and the view will be created using currenct user account.
since you are running the server on your own computer, I am assuming you have root access. Try using something like
ALTER VIEW brokenView DEFINER='newuser'
this passes the validation check here. As long as you are root when you do this, you should be able to recover your views.
I need to know if it is possible to dynamically bind a textbox residing within a datarepeater to a 'dynamically' created BindingSource. I am using VB.net. The database I am using is a MySQL database.
I have to use the connection dynamically due to the fact that the database my not permanently reside on the same server.
[edit]
ok, so it seams that I am a dolt when asking questions. The app that I am making is not web based. it is a simple (I hope) app that connects to a MySQL database, accesses a table so I can edit/view it. Current setup is using the Add DataSource wizard. I have successfully connected to the dbase dynamically using the mysql connector dll but without the textboxes set at design time to a datasource, I am unsure on how to 'link' them via the datarepeater.
Your connection string should be defined in your Web.Config, and if you move your database to a different server, it's just a matter of modifying the web.config entry. As long as you keep the connection string name the same, the BindingSource object will pick up the new value from the config.edit
In truth, the same concept should apply here as it does in the web app answer listed above.
All of your data objects should be hard-coded, and it's just the connection string (which you'll have to either ask the user for, or push out as update when the DB moves) which will get modified.
For example, create a App.Config file in your project. Have one of your configuration values be the connection string. This config value will be where you go to get the connection string whenever you need it. Then your wizard will be there to allow users to easily modify the connection.
then look in app.config
the conenction string should be there.
If it is not then you should put it in here as you can change this file at any time and not have to recompile your app.