cakephp-2.0

CakePHP find not returning correctly - missing model name

人走茶凉 提交于 2019-12-02 04:29:12
After performing a find on a model I would expect the result to be of the format Array ( [0] => Array ( [ModelName] => Array ( [id] => 83 [field1] => value1 [field2] => value2 [field3] => value3 ) ) ) However, what I appear to be getting is Array ( [0] => Array ( [0] => Array ( [id] => 83 [field1] => value1 [field2] => value2 [field3] => value3 ) ) ) Note the missing model name. I've only been getting this problem since migrating across to what appears to be a very poorly configured VPS that I now have full control over. My problem is, I can't think of anything that would cause this problem.

CakePHP 2.1 $this->Session->write is not working

不想你离开。 提交于 2019-12-02 03:51:22
问题 I included the 'Session' Component and the helper in my AppController.php Now, if I use $this->Session->write('App.testString', 'test); the Session is not created, or at least I don't receive the string when I do echo $this->Session->read('App.testString'); . Do I have to change any settings for Sessions to work? Inside a controller function I can write and read a session, but if I want to read the session inside a different function (of the same controller) I don't get a value back. 回答1: I

cakePHP File Download was not found or not readable

ε祈祈猫儿з 提交于 2019-12-02 03:47:46
问题 I've been struggling now for an hour trying to fix this. I used this to download file from app/uploads/ directory. It says the directory not found or not readable. Yet i checked it and it was there also the file using $file['File']['filename'] . I want to know what I am missing here.? $file = $this->File->findById($id); $extension = pathinfo($file['File']['filename'],PATHINFO_EXTENSION); $this->response->file('uploads'.DS.$file['File']['filename'], array( 'download' => true, 'id' => $file[

How to use “response” from any XMLHTTPREQUEST in CakePHP (2.5)

家住魔仙堡 提交于 2019-12-02 03:46:34
I got the action "pega" in controller Posts: public function pega($id = null) { $posts = $this->Post->findById($id); foreach($posts as $pok) { $foda = $pok['love']; } $this->set('foda', $foda); $this->set('_serialize', array('foda')); } In my layout I try to do a requestto catch the data from function "pega" and put inside tag html: <script> var xmlhttp = new XMLHttpRequest(); var url = "http://localhost:81/booklandia/posts/pega/<?php echo $post['Post']['id'];? >.json"; xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var out = JSON.parse(xmlhttp

CakePHP 2.1 $this->Session->write is not working

感情迁移 提交于 2019-12-02 02:10:57
I included the 'Session' Component and the helper in my AppController.php Now, if I use $this->Session->write('App.testString', 'test); the Session is not created, or at least I don't receive the string when I do echo $this->Session->read('App.testString'); . Do I have to change any settings for Sessions to work? Inside a controller function I can write and read a session, but if I want to read the session inside a different function (of the same controller) I don't get a value back. I found the solution: By default CakePHP uses the folder which is set in php.ini. This folder couldn't be

How to 'unlock' a field in a CakePHP form when it is part of a hasMany association

半城伤御伤魂 提交于 2019-12-02 00:49:18
I have a form that represents a RewardModifier table in our database. That RewardModifier hasMany RewardOption . My form is structured like this (image): So, the RewardModifier can have many elements on the page, each with many RewardOption items. The Problem The problem is, that users can delete sections of this form using Javascript, which essentially removes it from the DOM. When they do that, it breaks the security component, because the POST'ed fields do not match the token supplied when the page was generated. Now, I have been using unlockedFields to handle this before: $this->Security-

How can i test an Add function on CakePHP2.0

泪湿孤枕 提交于 2019-12-01 22:41:09
I have been told that we have to test also the functions created by Cake like add/delete... If i have a function like this one, how can i test it if it doesn't have any return, redirect or even a view? ( i use ajax to execute it) public function add() { if ($this->request->is('post')) { $this->Comment->create(); if ($this->Comment->save($this->request->data)) { $this->Session->setFlash(__('The comment has been saved')); } else { $this->Session->setFlash(__('The comment could not be saved. Please, try again.')); } } } Thanks public function add() { $this->autoRender = false; if ($this->request-

CakePHP 2.0 Select form Mulitple selected

被刻印的时光 ゝ 提交于 2019-12-01 19:04:54
Ok, so I have have this dropdown menu where you can select multiple values. Now lets say I want to edit my info and make a dropdown menu with multiple selected values. Trying to figure out how it goes, but no results. Lets say I have: $selected = array(3, 4); $options = array(1,2,3,4); echo $this->Form->select('Attendees', $options,array('multiple' => true, 'selected' => $selected)); I've used this code, but nothing is selected. Ok found a way, appearantly it needs to be like this: $selected = array(2, 3); $options = array(1, 2, 3, 4); echo $this->Form->input('Attendees', array('multiple' =>

Using email instead of username in CakePHP Auth Component

风流意气都作罢 提交于 2019-12-01 18:36:56
I am working on cakephp 2.x . my problem is i dont want to use username for logging .. i am taking the email and password from the user and verify this email and password from the database i have a table in my database name user and it has 3 fields id , email and password here is my code Model <?php class User extends AppModel { public $useTable = 'user'; } ?> AppController class AppController extends Controller { public $components = array( 'Session', 'Auth'=>array( 'loginRedirect'=>array('controller'=>'users', 'action'=>'admin'), 'logoutRedirect'=>array('controller'=>'users', 'action'=>

CakePHP - authentication component, using a different table name and column name

心已入冬 提交于 2019-12-01 15:10:58
Just for organization sake, I wanted to use a different table for the authentication component to check, but it doesn't quite work. While I can initially state: $this->Auth->userModel = "CoreUsers" plus set the loginAction to my proper MVC works to look at that table just to confirm it's there, but the login doesn't work, it only keeps returning an incorrect password. Something happens in the authentication component; I can't tell what makes it fail. When I rename my table to "Users", it works. The other part is I'd prefer to actually use the column name of 'email' rather than 'username' since