I need to create a custom function in request_handler.
Which file should I edit:
core\cake\libs\controller\components\request_handler.php
or
app\controllers\components\request_handler.php
I believe that core should be mantained has origin and all the changes should be made on app folder, is this right? Assuming it's correct, I should duplicate the file (from core to app) and add the functions I need or just create a new file with the new functions?
Thanks!
Which versuion of Cake is this? Seems like 1.3?
You should NOT edit the core under any circumstances. It is also not good to add a function to request_handler.
If you need this logic all over the application just implement it in the AppController's callback functions.
Related
I need to create a custom exception. But I don't know where to store the file and how I call the Custom Exception reference?
This Question/Answer did not work, this folder structure does not exist in this version.
My current folder structure:
Note: CakePHP 3.0.11
If you read the accepted answer on the question you reference you will see it doesn't matter where you place the exception as there is no Cake convention for where to put these. Using namespacing correctly the autoloader will find them.
Personally would put it somewhere like src/Error/CustomException.php (you can create the folder structure for yourself even if it doesn't exist), but at the end of the day it is up to you.
I have file with functions which I want to use everywhere in my application.
In raw PHP the way to do it is to call them in each file by include or require.
Is there any simple way in Yii to call this file once and use it everywhere?
Second question is to call the same file and use it in a particular controller.
You can require this file in main config of your appllication for example, or in beforeAcition method of application base controller if you have it.
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'components/some_funcs.php';
maybe this could help you THE DEFINITIVE GUIDE TO YII.
Using 3rd-Party Libraries
Yii is carefully designed so that third-party libraries can be easily integrated to further extend Yii's functionalities. When using third-party libraries in a project, developers often encounter issues about class naming and file inclusion. Because all Yii classes are prefixed with letter C, it is less likely class naming issue would occur; and because Yii relies on SPL autoload to perform class file inclusion, it can play nicely with other libraries if they use the same autoloading feature or PHP include path to include class files.
Below we use an example to illustrate how to use the Zend_Search_Lucene component from the Zend framework in a Yii application.
First, we extract the Zend framework release file to a directory under protected/vendors, assuming protected is the application base directory. Verify that the file protected/vendors/Zend/Search/Lucene.php exists.
Second, at the beginning of a controller class file, insert the following lines:
Yii::import('application.vendors.*');
require_once('Zend/Search/Lucene.php');
I am working with play framework and scala and I'd like to create several log files instead of using the default log file for everything.
I suppose I have to specify the route of the file(.log) I want to write in but I don't know how neither where. And I think I have to create a .scala file to define my logger but I don't know what to put inside.
Anyone knows how to do this?
Thanks in advance.
Configuration of the logging is explained in the documentation here : Settings Logger
As the title, is cakephp support file upload without uses of plugin or not ?
**I means any code that made by cakephp developers not include pure php code.
Not really, for a full implementation you will need a plugin or create your own logic. Cake does offer convenience methods based on the base PHP functions. The File & Folder utility is an example.
You can use component instead of plugin like this one and it should do the job, but I'm not sure is this what you are looking for.
OK, Cakephp is support file upload, I just have to set the name of form to use it.
I am trying to use the Configure class in CakePHP, but I'm not sure if I am using it correctly. I have read through the cook book and the API, but I can't seem to do what I want.
I have created a configuration file: app/config/config.php. I can directly edit this file and set variables in there and access them using Configure::read().
Is it possible to update the values of the configuration file from the application itself, i.e., from a controller? I have tried using Configure::write(), but this does not seem to change the value.
app/config/config.php isn't a file that's automatically loaded by Cake. Either move these variables into app/config/bootstrap.php or tell your bootstrap.php file to load your custom file. You could also put your variables in app/config/core.php, but I'd recommend against that. I tend to like leaving that file alone and adding/overwriting values in bootstrap.php.
According to the API, Configure is supposed to be used "for managing runtime configuration information".
You can use its methods to create, read, update and delete (CRUD) configuration variables at runtime. The Configure class is available everywhere in your CakePHP application and therefore CRUD operations performed on its data in any place, including a controller.
If you are looking for persistent storage, you could consider a database (SQL or NoSQL). I would not recommend using a text file, as it raises a lot of security concerns. Even if security is not an issue, a database is propably a more fitting solution.
More on the Configure class in the Cookbook.