cakephp-model

Cakephp use saveAll and specify which models only

为君一笑 提交于 2019-12-12 06:09:27
问题 Im new to relatively new to cakephp, right now I'm trying to use saveall() and save individual models depending on the role the user chose for the register. Here is my View: <?php echo $this->Form->create('User', array('type' => 'file')); ?> <fieldset> <legend><?php echo __('Add User'); ?></legend> <?php echo $this->Form->file('User.user_image'); echo $this->Form->input('User.name', array( 'label' => 'Nombre')); echo $this->Form->input('User.last_name', array( 'label' => 'Apellidos' )); echo

CakePHP Edit Not Loading foreign Table Data

白昼怎懂夜的黑 提交于 2019-12-12 04:46:05
问题 I am trying to get my edit to work I need the contact detail data to load when the user data loads. I have set the data in a similar manner to how I am retrieving the list of roles. I also don't know how to retrieve according to the model currently I was hard-coding it to retrieve 28. Would greatly appreciate any help provided. public function edit($id = null) { //Populate roles dropdownlist $data = $this->User->Role->find('list', array('fields' => array('id', 'name'))); $this->set('roles',

CakePHP: paginating with search logic in a model

本小妞迷上赌 提交于 2019-12-11 18:29:15
问题 I'm having trouble paginating a search result. My setup is as follow. I have a search form at myapp.com/searches/products with view (has search form) .../app/views/searches/products.ctp . I am employing a Searches controller that uses the Product Model for this search query. Product has action search() with the search logic ( $this->find(...) ). The search result is displayed below the form in the view. How do I go about performing something similar to $this->paginate() , which is normally

CakePHP pass custom query from controller into model paginate()

亡梦爱人 提交于 2019-12-11 05:49:10
问题 I am using Cakephp 2.X version Im going to run sql like: SELECT field1, field2, field3, field3, ( IF(LOCATE('abc', field1), 4, 0) + IF(LOCATE('abc', field2), 3, 0) + IF(LOCATE('abc', field3), 2, 0) ) AS score FROM sometable WHERE ( (field1 LIKE '%abc%') OR (field2 LIKE '%abc%') OR (field3 LIKE '%abc%') ) ORDER BY score DESC this sql is generated by code dynamically. So this sql need to be passed into paginate() function in order to do the pagination by cakephp. It seems that cakephp

$this->params returns null in cakephp model

假如想象 提交于 2019-12-11 02:22:35
问题 I decided to add some extra data about the controllers and actions in some model beforeSave as follows: //in the model public function beforeSave() { $this->data[$this->alias]['path'] = 'blah blan'; debug($this->params); die(); //for debugging! } The printout of debug returns null ! The model I uses is the Comment model of the comments plugin. I need to access params to get the current controller, actions and some url parameters. Indeed, I plan to change the way that comments plugin lists the

Transaction management with multiple models using single transaction commit and rollback

六眼飞鱼酱① 提交于 2019-12-10 14:56:41
问题 I am new to cakephp. I want to know if it is possible in cakephp to to handle multiple model commit and rollback with single transaction. I want to do some thing like this <?php function add(){ $transaction = begintransaction; if(model1->save()){ if(model2->save()){ if(model3->save(){ } else{ $errorFlag['model3'] = "Error in model 3"; } } else{ $errorFlag['model2'] = "Error in model 2"; } } else{ $errorFlag['model3'] = "Error in model 3"; } if(empty($errorFlag)){ //no error in saving the

Cakephp HasMany + SaveAll doesnt work

南笙酒味 提交于 2019-12-08 05:22:50
问题 Im trying to do a hasmany saveall() but it does not work. I have a Model Carmodel hasMany CarmodelsImage When i try to save, the array passed is: [CarmodelsImage] => Array ( [0] => Array ( [name] => teste [carmodel_id] => 1 ) ) In the controller i have $this->Carmodel->saveAll($this->request->data) but it does not work. I need some help. I know this question was already posted but I read every answers and it not work. Thanks 回答1: Your requested data needs to be an array like in the following

CakePHP model relation having 2 foreign key on the same table

我们两清 提交于 2019-12-07 12:36:52
问题 I have this database design Applicant Table id | country_id | country_now_id Country Table id | name The country_id is an FK to the Country Table, and the country_now_id is also an FK of Country Table. My question is how would I write this one in Model relation? I have this code: class Applicant extends AppModel { public $belongsTo = array( 'Country'=>array( 'className'=>'Country', 'foreignKey'=>'country_id' ), ); ..... I don't know how to add the country_now_id and put it in that relation. I

Getting names to show in dropdown list with cakephp

匆匆过客 提交于 2019-12-06 10:37:50
I want to show the names of all our project leaders in a dropdown list. The project leaders are only some of the employees that work in the company. Here are my tables: project_leaders ,----,----------------, | id | hr_employee_id | |----|----------------| | 1 | 18 | '----'----------------' projects ,----,------,-------------------, | id | name | project_leader_id | |----|------|-------------------| | 1 | cake | 1 | '----'------'-------------------' hr_employees ,----,------,---------, | id | name | surname | |----|------|---------| | 18 | joe | dirt | '----'------'---------' My

Retrieving inserted IDs from saveAll() in CakePHP

こ雲淡風輕ζ 提交于 2019-12-03 03:18:18
Using saveAll() to save multiple records in CakePHP, I am able to save them successfully in a table. But the problem arises while retrieving the IDs of those saved rows. LastInsertID() returns only a single last ID here. How can I get all the last inserted IDs which I have inserted using saveAll() ? afterSave function is called after each individual save in a saveAll execution, so you could do: In your AppModel class AppModel extends Model { var $inserted_ids = array(); function afterSave($created) { if($created) { $this->inserted_ids[] = $this->getInsertID(); } return true; } } You can place