cakephp-3.x

Cakephp : display data in a table with other table's data

孤街浪徒 提交于 2019-12-12 03:56:29
问题 I'm displaying my users in a table, and I am retrieving the company name and city with company_id users : id lastname firstname company_id role 1 doe john 2 author 2 deo jenne 2 admin 3 deus Joe 1 admin 4 Stewart Rob 1 author companies : id name city 1 New-York Company New-York 2 Paris Company Paris user display : <?php foreach($users as $user):?> <tr> <td><?= $user->lastname?></td> <td><?= $user->firstname?></td> <td><?= $user->companies->name ?></td> <td><?= $user->companies->city?></td>

Label for Select Form Helper

荒凉一梦 提交于 2019-12-12 03:47:00
问题 I"m having trouble with CakePHP3's Form Helper class. When I create a text input field like this: echo $this->Form->input('fieldname'); When the input field is "required", a label appears in bold. This is fine. However, when I create a select field like this: echo $this->Form->select('fieldname', [1,2,3,4,5]); The select field is created however there is no label at all. I can add it manually using: echo $this->Form->label('fieldname'); However in cases where the select is a required field,

Query builder fetch data in cakephp 3.2

最后都变了- 提交于 2019-12-12 03:44:55
问题 I am using this below code to sum up all my wallet balance . $query = $this->Wallets->find(); $query->select([ 'count' => $query->func()->count('id'), 'total_price' => $query->func()->sum('amount') ]) ->where(['status' => 4, 'user_id' => $user_id]); pj($query); echo $query->total_price; exit; out put of pj($query); [ { "count": 2, "total_price": 700 } ] Here i have tried to get single individual value using below query echo $query->total_price; I am not getting it. What is the proper syntax

How to install a plugin manually in CakePHP 3?

纵饮孤独 提交于 2019-12-12 02:59:15
问题 I am unable to use Composer and thus have to install CakePDF plugin manually, but following examples from official CakePHP documentation does not seem to work. So here is installation flow that I have followed: 1.) Copied the plugin to app/plugins/CakePdf 2.) Updated the app's composer.json file, like following: "autoload": { "psr-4": { "CakePdf\\": "./plugins/CakePdf/src", "CakePdf\\Test\\": "./plugins/CakePdf/tests" } }, "autoload-dev": { "psr-4": { "App\\Test\\": "tests", "Cake\\Test\\": "

cakephp 3 response withFile and video tag

别来无恙 提交于 2019-12-11 18:29:28
问题 I've used this code to send a video using an action in CakePHP: $response = $this->response->withFile(WWW_ROOT.'Component.webm',['download' => false]); and inside template: <video class="img-responsive" controls> <source src="<?= Router::url(['controller' => 'posts', 'action' => 'stream', $id]) ?>" /> </video> everything works great in Microsoft Edge. But when I view the page inside Google Chrome and I start playing the video I cannot visit any other page of my site, until the video is

Merge index and add action into form in cakephp 3.5

家住魔仙堡 提交于 2019-12-11 15:22:17
问题 I'm a beginner to cakephp and now I'm using cakephp 3.5. I'm having a problem when I need to create a form. The form that I want to create is from index view and it have multiple checkbox. My problem is whenever I click the checkbox, the data did not save. The form's name is existing_question.ctp. Here is the code. <?php /** * @var \App\View\AppView $this * @var \App\Model\Entity\Question[]|\Cake\Collection\CollectionInterface $questions */ ?> <nav class="large-3 medium-4 columns" id="actions

Infinite Login Loop after CakePHP 3.6 update

本小妞迷上赌 提交于 2019-12-11 11:54:04
问题 in my application, based on CakePHP, I'm using. When I'm logging in using the URL /manager/login (corresponding to LoginController, Managerr prefix) everything is OK. When I logout or I use /manager the result is the following: /manager/login?redirect=%2Fmanager%2Flogin%3Fredirect%3D%252Fmanager%252Flogin%253Fredirect%253D%25252Fmanager%25252Flogin%25253Fredirect%25253D%2525252Fmanager%2525252Flogin%2525253Fredirect%2525253D%252525252Fmanager%252525252Flogin%252525253Fredirect%252525253D

How to use $this->autoRender = false in cakephp 3.6.10?

一世执手 提交于 2019-12-11 09:17:09
问题 I am trying to display the test data on the screen by running function test() in the pagesController. Used $this->autoRender = false for it, but it is still giving me error: Please help me out. I think some version problem is there, but I can't figure it out. Thankyou. 回答1: Cakephp by default takes Pages controller's display actions as a home page. display function manages pages and subpages itself that is why you are getting error. Either you can change your default home page in your /config

Cakephp 3 - How to send POST request from controller action?

大城市里の小女人 提交于 2019-12-10 11:52:47
问题 I need to send POST request with parametrs without using form. I have page where user set a few parameters, then press the button and new record in database is created. After that I need to send data from database to the other webpage using post method. Do You have any sugestion how to prepare that request? 来源: https://stackoverflow.com/questions/52282299/cakephp-3-how-to-send-post-request-from-controller-action

How to check CSRF token using AJAX and CakePHP 3 when user is not logged in?

半城伤御伤魂 提交于 2019-12-10 11:47:04
问题 So I made my site live and I am entering into the public realm where people aren't always nice. I just started learning about CSRF and saw that it was something I needed when I made my cakephp 3 site live. As seen here! I added the csrf component and the security component to my site, but I have 1 major problem. Now, when users want to sign up they can't. I use a custom form for stripe to send payment, but also add a user using ajax to my database. The user gets added first and then the