cakephp-2.0

Use a Custom CakeResponse Class in CakePHP 2.1+

こ雲淡風輕ζ 提交于 2019-12-25 04:08:11
问题 I am trying to use a Custom CakeResponse class however none of my current work nor current searches have led me to a solution towards actually using one. So let's call my custom CakeResponse class AppResponse : AppResponse is in Lib/Network <?php App::uses('CakeResponse', 'Network'); class AppResponse extends CakeResponse { } Based on this blog post http://mark-story.com/posts/view/cakeresponse-in-cakephp-2-0 it appears that one should be able to use this code to override the CakeResponse and

Saving data with cakephp won't work

亡梦爱人 提交于 2019-12-25 04:03:46
问题 I'm trying to load , edit and save a record with CakePHP 2.0 but I get a generic error during the save method that don't help me to understand where is the problem. if I try with debug($this->User->invalidFields()); I get an empty array , but I get false from $this->User->save() condition. Here is the controller action where I get the error: public function activate ($code = false) { if (!empty ($code)) { // if I printr $user I get the right user $user = $this->User->find('first', array(

Error PDO Exception SQLSTATE[42000] when using CakeDC Users plugin

纵然是瞬间 提交于 2019-12-25 03:43:20
问题 Iam using cakephp 2.2.1 and trying to use the cakedc users plugin, when I try to create a user I get the following error, can anyone give some tips or advice to resolve this error - I have loaded all tables using the migrations plugin. Thanks in advance :). 2013-04-07 06:31:33 Error: [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

cakePHP- setting loginRedirect from beforeFilter for admin role

五迷三道 提交于 2019-12-25 02:36:10
问题 I am facing this weird problem. I am trying to change the default loginRedirect of the admin role from that of normal user. U have the auth key in the AppController's component variable set up as follows : 'Auth' => array( 'loginRedirect' => array( 'controller' => 'donors', 'action' => 'index' ) ) Now in the beforeFilter callback I have this set up: if($this->Auth->user('role') == 'admin'){ $this->Auth->loginRedirect = array( 'controller'=>'users', 'action'=>'admin_index', 'prefix'=>'admin',

how to connect two DB in cakephp

本小妞迷上赌 提交于 2019-12-25 02:27:10
问题 I have working on a project which contains two DB , the common tables are in main DB and some specific tables are in separate DB. I need to connect the DB dynamically because the second DB is based on the user they log-in in site . We get the details from DB and then create a DB settings and connect . Can anyone help on this concept. 回答1: i have used this method function dbConnect($config = array()) { $config['datasource'] = 'test'; ClassRegistry::init('ConnectionManager'); // echo "<pre>"

cakephp download png file

我们两清 提交于 2019-12-25 02:22:06
问题 I dynamically generate png files which after clicking "generate" button appears "under" link. "generate button : click" ---> <a href="new_generated.png">DOWNLOAD</a> After clicking link DOWNLOAD I wish content of link(in my case png) start download - no open in another window but download! I am using cakePHP. Can I please for help? 回答1: Alternatively if you are using Apache web server and have mod_headers enabled you can use an .htaccess file to force download of the png files. Create a

CakePHP: One column -> one TRUE

↘锁芯ラ 提交于 2019-12-25 01:55:08
问题 Hope someone could help me with this: I would like to have a column that will contain one and only one TRUE value. I want to set a value of TRUE (or '1') to a row and be assured that the remaining rows are FALSE (or '0'). How this could be achieved with CakePHP? 回答1: You can't enforce this at the database level (well, you can if you use triggers) so you'll have to enforce it using Model::beforeSave() Something along the lines of: public function afterSave() { if ($this->data['Model']['field']

Redirect all webpages under webroot to login page in Cakephp

断了今生、忘了曾经 提交于 2019-12-25 01:44:09
问题 I am using cakephp 2.4.5. I would like to redirect all users who have not logged in to a login page. I basically followed the instructions available here. In summary, the important part is the following code to AppController.php public $components = array('Session', 'Auth' => array( 'loginRedirect' => array('controller' => 'users', 'action' => 'index'), 'logoutRedirect' => array('controller' => 'users', 'action' => 'login'), 'authError' => 'You must be logged in to view this page.',

How to implement distance queries in CakePHP?

做~自己de王妃 提交于 2019-12-25 01:36:01
问题 I have a query (from Google Maps) like so: SELECT ( 3959 * acos( cos( radians(MY_LAT) ) * cos( radians( LATITUDE ) ) * cos( radians( LONGITUDE ) - radians(MY_LONG) ) + sin( radians(MY_LAT) ) * sin( radians( LATITUDE ) ) ) ) AS distance FROM zips ORDER BY distance I would rather this be a custom find in Cakephp, so how do I do that? MY_LAT and MY_LONG are params passed in. LATITUDE and LONGITUDE are columns in zips table. 回答1: You can use a behavior like the geocoder behavior ( https://github

cakePHP HABTM don't save

帅比萌擦擦* 提交于 2019-12-24 22:50:28
问题 I have looked into all threads I could find about this Topic, but nothing solves my Problem. I have a 'customers' table and an 'employees' table which should be connected via the 'customers_employees' table. In my Form I can select the employees, but when I want to save the data he only save the 'created' and 'modified' entry and not the keys. The employee has an string id which is CHAR(36). This is my entry in the 'employee' model: public $hasAndBelongsToMany = array( 'Customer' => array(