cakephp-3.x

Save data to another model cakePHP 3.5

本小妞迷上赌 提交于 2019-12-04 05:51:31
问题 I'm still beginner in cakephp. I have table question and questionQuizzes. I have created the form named existingQuestion in question controller and want to save it in table questionQuizzes. However, the form cannot be saved. I have followed this example but it still cannot be saved. This is QuestionController public function existingQuestion() { //echo "here<br><br>"; //$QuestionQuizzesTable = $this->loadModel('QuestionQuizzes'); $questions = $this->paginate($this->Questions); $questionQuiz =

How to select fields of a contained association?

偶尔善良 提交于 2019-12-03 18:07:49
问题 I would like to execute the following query where I'd like to read only the necessary fields from associated. I used a dot notation in select() below to better explain what I want. Basically the select() seems to concern Users only. Is it possible to specify the fields of Sites ? $orders = $this->Orders->find() ->contain([ 'Sites.Users'=> function ($q) { return $q ->select([ 'Sites.id', 'Sites.user_id', 'Users.id', 'Users.name', 'Users.owner_id', 'Users.firstname', 'Users.lastname' ]) -

Confusing Validation vs. Application Rules in CakePHP3

蓝咒 提交于 2019-12-03 13:09:55
Multiple questions about validation which may belong together, because they are all kind of adressing the new validation concept in CakePHP 3. I have read the chapters ( 1 , 2 , 3 ) in the cookbook multiple times but honestly I don't understand how to do it the right way. I also know there is currently a issue/discussion at GitHub about the Validation in CakePHP3 which may address the same topic. Validation errors are triggered e.g. with patchEntity. So I would think it is better to ALWAYS check/display errors BEFORE doing the save action: // src/Controller/UsersController.php public function

cakephp 3.x mail is not working properly in live server

白昼怎懂夜的黑 提交于 2019-12-02 19:30:26
问题 I am using cakephp 3.x. The email is working properly in localhost but not in case of live server. It is simultaneously giving error like "Transport class "SMTP" not found.".I have been stuck from long time. Please provide good solution for it.Why it is happening and what should I have to do? here is my config/app page 'EmailTransport' => [ 'default' => [ 'className' => 'SMTP', // The following keys are used in SMTP transports 'host' => 'ssl://smtp.gmail.com', 'port' => 465, 'timeout' => 30,

Using multiple valueFields in find('list')

只谈情不闲聊 提交于 2019-12-02 16:50:22
问题 Trying to use multiple fields in my find method - $users = $this->AdressesUsers->users->find('list', [ 'keyField' => 'id', 'valueField' => ['firstname','lastname'], ]); Works, kinda. Because the two get seperated by a semicolon. Also tried using a mutator method, but this failed badly. In my Function 'valueField' => function ($e) { return $e->author->get('full_name'); } In my Entity User protected function _getFullName() { return $this->firstname . ' ' . $this->lastname; } 回答1: I would never

How to continue a CakePHP 3 session in a regular PHP script?

岁酱吖の 提交于 2019-12-02 13:59:17
问题 My situation is the following. I have a cakephp project and a seperated plain php script running on the same server. When I use my client browser to connect to the cakephp project, it builds up a session as it should. Now I want to continue the session data with my plain php script. Again I use the same client browser to access the plain php script (so the request meta data should be the same and the session should be recognized) and I set cakephp session option to PHP. 'Session' => [

QueryBuilder limit is working for only first row in cakephp 3.2 [duplicate]

Deadly 提交于 2019-12-02 12:28:09
This question already has an answer here: How to limit contained associations per record/group? 1 answer Hii i am new to cakephp 3.2 v. Here i have used model association (hasMany). Here in bind section (campaign_videos) ,i want to fetch only one record , so for this ,i have put below code to manage it. my actual data in db. [ { "id": 1, "user_id": 95, "campaign_videos": [ { "id": 1, "campaign_id": 1, }, { "id": 3, "campaign_id": 1, } ] }, { "id": 2, "user_id": 95, "campaign_videos": [ { "id": 2, "campaign_id": 2, } ] }, $fetchCampaignFirst = $this->Campaigns->find()->contain(['CampaignVideos'

CakePHP 3.7.5 Retrive data of a field into the controller

五迷三道 提交于 2019-12-02 11:55:36
I apologize in advance if I am opening a question that may have already been asked, but I don't think I have found any results. I have a problem with the following CakePHP code portion: $unavailable_resource_ids = $this->Resources->Unavailabilities ->find() ->select(['resource_id']) ->matching('Bookings', function ($q) { return $q->where([ 'Bookings.booking_status_id NOT IN ' => [6, 4, 3] ]); }) ->where([ 'OR' => [ [ 'Unavailabilities.start <= :start_date', 'DATE_ADD(Unavailabilities.end, INTERVAL '. $recovery_time .') >= :end_date' ], [ 'Unavailabilities.start <= :start_date', 'DATE_ADD

Save data to another model cakePHP 3.5

自闭症网瘾萝莉.ら 提交于 2019-12-02 10:02:25
I'm still beginner in cakephp. I have table question and questionQuizzes. I have created the form named existingQuestion in question controller and want to save it in table questionQuizzes. However, the form cannot be saved. I have followed this example but it still cannot be saved. This is QuestionController public function existingQuestion() { //echo "here<br><br>"; //$QuestionQuizzesTable = $this->loadModel('QuestionQuizzes'); $questions = $this->paginate($this->Questions); $questionQuiz = $this->QuestionQuizzes->newEntity(); //print_r($this->request->getData()); //die(); if($this->request-

Full URLs in emails in CakePHP unittest

孤者浪人 提交于 2019-12-02 07:45:34
问题 I would like to get full URLs inside emails that get triggered by my tests in CakePHP 3.2. I tried with the full-options for $this->Html->image('image.jpg', ['fullBase' => true]) and $this->Url->build('/', true) but they don't seem to work in tests. How can I force full URLs in emails while testing? 回答1: There is no host when running an app in the CLI environment as it's not a web request. You'll have to configure the base URL on your own. Quote from the docs: App.fullBaseUrl The fully