Retrieve configurations that are saved in db - cakephp

I saved all my system wide configurations in db. How do i make the configurations that I have saved in db available everywhere. These need to be available everywhere --in the model, view, controller, component, element etc.

Are you trying to override the Configure::write() function with values that you are storing in the DB? If not, then create a Settings model for your external settings and then pull that data when you need it in the controller. You can then pass those settings to a view (and in turn elements), by following the normal MVC process.
Follow this process:
Create Settings Model
Add model to AppController's $uses array
Perform a find for the settings in your controller -- now the data
is there
Pass the settings data to your view $this->set('settings',
$settings);

Related

Best practice for loading non model data in ExtJS

Let's assume that I have 2 tables in my database, a user table and a folder table. They are matched by two models (beans) in my backend java code and similarly by to models in my extjs client side. Using viewmodel architecture, I want to create a form that shows the username and the amount of folders they have created using viewmodel bindings. Each folder in the database has a CREATE_USER_ID field that contains the id of the user that created the folder. How do I go about loading the required data?
Viewmodels are not designed to load data directly (and not designed to load non model data at all). You've got two options:
Go model (recommended). Two sub-options:
Add folder_amount field to your client side user model. On the server side this does not necessarily need to be added as well as you can adjust your API feeding data to client to add that field dynamically.
If you want to keep your client models exactly matching their server mates, use viewmodel in conjunction with associations (see example here, scroll down to Associations) to load folders themselves, though in the UI only show the amount of them. Mind that you don't need to load all folder fields but just their IDs.
Stick to your own fancy non model approach, but this won't have anything to do with viewmodel bindings. This may be, for example, making an AJAX call to retrieve the number of folders when user data is rendered in the UI.

Accessing an Object from other Method

I am trying to access view objects from Java method.
These objects are not viewed in my page. so I cant use getter and setter methods.
Is there a way I can retrieve data from these view objects using SQL queries?
Accessing view objects from the view layer is not a good practice.How ever if the required view object which you need to access is added to application module then you can access that from the model layer
methods(VOImpl and VORowImpl) pertaining to the view object used in the jsf page.
Just access the app module first and then get the required ViewObject and you can perform the required query on that.

Retrieve JSON Object and Store Values in Django

I want to retrieve a JSON object from an external API, read it's values, and store it in my database. The issue I'm having is figuring out where to put the code. Ideally, I would want to do this from the admin interface. It's something that only me as an admin should be able to do . I can code the view for retrieving, reading, and saving the data, but I'm at a loss as to how I'd make this available from the admin interface.
You can write the view as you describe and use something like https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-views-to-admin-sites to hook it in to the admin structure.
There may be a better way, but when I've done this in the past, I've also then customized the default admin index.html template to link to my custom admin view.

Ext JS and loading data into a form

I have build a simple MVC application where I have a form and I need to load data into it.
I'm wondering if I should load this data using a store or directly using the model class. I have already a store for my grid.
So I see this 3 option.
Load data using Model class
Load data using the existing store (a grid uses this store already)
Create a second store and load my data using it.
If your store uses the same model and the data (record) you edit will defiantly be loaded in that store (for example if you open the form on a double-click of a gridrow) or can be inserted into it I recommend you to go with the store approach.
If you edit a record (model-instance) that will not necessarily loaded into the grid-store the you should load the data using the model.
A second store will only be necessary if both points above are true and you also wan't to batch multiple record (model-instance) edits from that form into one request to the server.
A third option is to bind the form directly to the server, but I recommend you to use the model-approach.
Note that if you need a different proxy for the store and the model
simply set one on the model and one on the store. By default the store
will inherit the proxy of the model but never the model the proxy of
the store

How can I use Backbone.Model.save() if my whole app and data is local?

I'm making a totally local Backbone app, no server-side included, and I provide the app with some initial local data. The data is actually the Collection data which is a json file and stored in a folder called data. So I provide the Collection with a url attribute which is data/datalist.json and use this.collection.fetch() to get the inital data. All works well.
But I want any update happens in View would save changes to the corresponding Model data in this Collection json data file. It seems that this.model.save({name: newName}) doesn't work for me. Every time I refresh the whole page, the app will still show the inital data file. So how should I change the data file when a item in View is updated, deleted or created? Do I need to set a url attribute in Model?
Model.save calls the Backbone.sync method, which by default maps CRUD functions to a REST api. If you want to use something other than REST for save/update/delete, then you need to override Backbone.sync.
There is a local storage plugin that overrides sync on Github, which is endorsed by Backbonejs: Backbone.localStorage
This plugin should persist your data while the app is running. You may need to extend it if you want to write changes to your filesystem (not sure, haven't used it myself). Hopefully this gets you started.

Resources