Need to log into a database table (logs) all major actions which took place in my app. The actions, for example, would be login/logout, view, add, update, etc. So, every time somebody logs in or, say, views a particular record - that would be logged in the database table.
I would like to call that method from all controllers in as simple way as possible - something like logIt($action, $object, $note) - as this would be dotted around the place, in every controller. It should also be reasonably efficient.
Do you have any suggestions? What would be the best way to do something like that?
Thanks guys. Regards from a CakePHP newbie.
You can use $this->log($data,'log_file'); anywhere in cake (model, view, controller). The data will be logged to tmp/logs/log_file.log
If it needs to go into DB, you'll need to setup a log method in app_controller, load the model yourself. And call that log in any controller you need.
Personally I think Anh Phams answer is a lot more "cake" and scalable, but if you need that list to be updated in real time then you'll have to put it into the DB I guess.
The best way to do this otherwise would be a custom component of some sort, which you could attach to your controllers as you see fit. Of course you could always create a simple method in your AppController, which loads a 'log' model and saves a record when you call it.
Related
I need to change log saving place from DB to files. I found only one way - rewrite Mage_Log module resource models and modify save() function for every resource model, but, as I understand right, it's not very good way. Please, tell me, how can I save logs into files, but not into DB (eg: visitor logs)?
You'll need to override app/code/core/Mage/Log/Model/Resource/Vistor.php.
In there, you'll find several places where it's writing this information into the DB which makes your site that much slower.
To answer your question, you'll need to change the following method(s):
_saveUrlInfo($visitor)
_saveVisitorUrl($visitor)
_saveCustomerInfo($visitor)
_saveQuoteInfo($visitor)
For those of you who may have landed on this page looking for information on how to disable the logs all together, you can find instructions here:
http://www.axertion.com/tutorials/2012/12/how-to-disable-magento-logging-to-the-database/
I noticed that salesforce doesn't allow to override control function for all objects.
Say if you want to do something whenever objects get saved there is no way to attach the action
unless you create a custom page and include either standard controller or extension. Or if you want
to add the same meta-tag on all pages I run into this limitation. Is there better way to do this?
Generally - no. Roughly speaking if Salesforce doesn't allow you to do something it usually means there's pretty good hint you're doing in it wrong. I realize it sounds like I'm a fanboy but in reality - can you expand your question with concrete example why would you want to do something like that? For example governor limits are evil, annoying etc. - but they force you to write effective code that doesn't strain the database too much.
if you want to do something whenever objects get saved
That's what triggers are for. Ask yourself a question if the "action" you need to make should happen only from web UI or also when performed from API (mass data load, a smartphone application etc).
if you want to add the same meta-tag on all pages
You could maybe pull off similar result by adding a component to the sidebar. It won't cover all cases (like accessing Reports/Dashboards) but it's hard to say more without knowing what you're really after. Then again - custom VF page overrides won't help you when it comes to Reports either.
I wanted to add this as a comment, but was unable to.
Anyways, For the example that you mentioned in the comment, You can add that jQuery plugin in the Home page side bar component and activate the plugin only on those custom objects where you wnat to run this plugin. You might already know that we can deduce which object a record belongs to by looking at the 1st 3 letter of the record Id, using this logic, check if the record belongs to the custom object you want your plugin to act on and run the plugin.
But As eyescream has pointed out adding script in side bar has its own limitations: you cannot use the global variables , side bar components are not loaded on the reports and dashboard tabs etc.
-ಸಮಿರ್
I am now building my first joomla component.
I have 3 tables in it:
__questions
__resaults
__display
I also need the Joomla user table:
__users
I have a single view:
view.questions.html
this view gets data and also needs some database functions. It needs to:
Get information from the user table.
Get information from the resaults table
Get information from the display table
-SET- information to the reaults table
Now, I know Joomla is built with MVC architecture. This, I assume, means no dealing with database in views.
Where should I store the database hendling functions, and how can I call them in the front end?
The function dealing with questions is in the question view model, no problem, but what about the other tables? Should I put the functions dealing with them in the question model as well, the helper file, or make models for each other table, and call them from the question view? If i should make other models, how do I call them from the question view?
Thank you very much for your help!
Create a model for each table.
You will then instantiate them from the controller to make them available to the views.
You can save a lot of time and also learn a lot by using the Component Creator: http://www.notwebdesign.com/joomla-component-creator/ It will do all the MVC stuff for you.
When I try to create some entities I don't see the option to input fields. I just see the SaveEntity button.
However I can view all the existing entities.
What is very strange is - there is another entity called VideoEntity for which the create did not work yesterday but works today.
Can somebody help me with this seemingly unpredictable tool ?
Regards,
Sathya
i think the console knows what properties each entity has based on existing data, rather then your models. and the data is only updated periodically. when did you upload your app? maybe waiting a few hours will give the console time to update.
alternatively, you could use the remote api to add your entities, or write a small snippet and upload such as ...
VideoStatsEntity(app='home', ip='116.89.52.67', params='tag=20130210').put()
Writing a simple interface to the data-store to allow you to edit/create models is probably the best thing to do in this case. You know what they contain so you can adjust your interface accordingly, rather then waiting for the admin interface to "catch up" as Gwyn notes.
I believe that there are some property types that are impossible to add via the admin interface that you are using so you'll probably get to the point sooner rather then later of creating a custom interface.
The admin datastore view is good for quickly checking out the contents of the datastore, but ever tried paging through 100's of entries? Not fun.
I'm trying to make an App-wide media-upload which should have the possibility of being accessible from every controller/model.
I thought of on table media which holds record of all uploaded files, my schema looks like this:
id
controller //to keep the reference from which controller the file was uploaded
foreign_key //since files should be uploaded to specific records, I need this id
filename
extension
fullname
size
created
modified
I'm not sure what would be the best approach in doing this. I've thought of components, plugins and a behavior but still am unsure.
My App has many different controllers with different records.
For example it manages projects and should now be able to attach PDFs to specific projects from within the project-edit mask.
Since this is a feature needed by other controllers, too I want to write it application wide.
I'm pretty sure I need a helper to call the upload-function from within the masks.
May something like: echo $this->Media->uploadMask(); which provides me with an ready uploading-mask for the controller and id I'm editing at the moment.
But I don't know which route I should call for the upload. Something like /media/upload would be very good, but I'm not sure if this fits correctly into the MVC-approach.
Would it be better to call it from my specific controllers? Or is an AJAX-upload to just a normal controller/model like better?
What you are describing is a Behaviour, which is basically an object of methods that can apply to any model. For controllers there are also Components.
There are already a couple of established upload behaviours for CakePHP you should check out: Meio Upload which is good for basic image manipulation and also the CakePHP Media Plugin which is more advanced and more recently updated.