cakephp-3.0

Redirect to referrer not working after Login

主宰稳场 提交于 2019-12-20 06:06:37
问题 After logging a user in, I want to redirect them back to where they came from but It's not working properly in CakePHP 3.5. Here are the required info's to help me figure out this problem. URL while login(session time out), http://dev.scys.com/db/admin?redirect=%2Fadmin%2Fstatuses This is my Auth config, $this->loadComponent('Auth', [ 'loginAction' => ['controller' => 'Admins', 'action' => 'login'], 'loginRedirect' => ['controller' => 'Admins', 'action' => 'index'], 'logoutRedirect' => [

CakePHP 3.0 cannot get 2 items from 1 table

主宰稳场 提交于 2019-12-20 05:36:04
问题 In a football match i have 2 clubs "Home-Club" and "Away-Club" . I have created table "match" and "club" in MySQL. In "match" table has 2 foreign key "home_id" and "away_id". I'm using cakePHP to show list matches, match information contain names of "Home-Club" and "Away-Club". How to get name of "Home-Club" and "Away-Club" in template file ( .ctp file ). For now I using this code in the template file: $match->club->name Code in Controller: public function index() { $this->paginate = [

How to create CSRF token for Cakephp 3 PHPunit testing?

限于喜欢 提交于 2019-12-20 04:49:23
问题 I am trying to get my unit tests working again after enabling CSRF tokens and SSL in my CakePHP 3 app. How do I create or generate a token for a test like the following? Or do I just disable it for testing purposes? public function testLogin() { $this->get('/login'); $this->assertResponseOk(); $data = [ 'email' => 'info@example.com', 'password' => 'secret' ]; $this->post('/login', $data); $this->assertResponseSuccess(); $this->assertRedirect(['controller' => 'Users', 'action' => 'dashboard'])

Select all except one field in cakephp 3 query

≡放荡痞女 提交于 2019-12-20 04:16:48
问题 I just want to select all fields except one field in cakephp 3. Ex. $this->select('fname', 'lname', 'mname', 'email', 'password', 'status', 'created', 'modified'); Here i want to select all fields except created and modified because my other table have apprx 30 fields and i want to select 28 fields and don't want to mentioned each and every field in select function because it is time consuming. Can you please suggest a better way. 回答1: As of CakePHP 3.6 the selectAllExcept() method has been

How to we use the SoapClient in Cakephp…?

▼魔方 西西 提交于 2019-12-19 06:57:51
问题 I have enabled SOAP in my local server. My code is: ini_set('soap.wsdl_cache_enabled', '0'); ini_set('soap.wsdl_cache_ttl', '0'); $client = new SoapClient('web_url'); $session = $client->login('username', 'pwd'); $result = $client->call($session, 'function_name', '<id>'); print_r($result); Here it's executed successfully when I run the code on separate php file. But I got this error: Error: Class 'App\Controller\SoapClient' not found when I try to run the code form CakePHP action. Please

installing cakephp 3 manually, without composer

℡╲_俬逩灬. 提交于 2019-12-19 05:06:29
问题 I need to install CakePHP 3 in an old-fashioned upload-unzip-run way. The archive I've downloaded from cakephp/cakephp/tags does not contain the default folders like webroot , Model etc., which means it's not complete. The official documentation does not cover this. Here's a relevant Github issue I found, but the person ends up still using Composer. There's also cakephp/app and it seems to include those missing files, but it's not mentioned in cakephp/cakephp 's composer.json, and even if I

Disabling CSRF on a specific action CakePHP 3

為{幸葍}努か 提交于 2019-12-19 04:09:53
问题 So, I have a table that is auto-generated using DataTables. An action in my CakePHP grabs the data for that table, and formats it into JSON for datatables to use, this is the formatted JSON: <?php $data = array(); if (!empty($results)) { foreach ($results as $result) { $data[] = [ 'name' => $result->name, 'cad' => $this->Number->currency($result->CAD, 'USD'), 'usd' => $this->Number->currency($result->USD, 'USD'), 'edit' => '<a href="' . $this->Url->build(['controller' => 'Portfolios', 'action

CakePHP query closest latitude longitude from database

a 夏天 提交于 2019-12-18 14:55:44
问题 In a CakePHP (v3) application, how can I retrieve the closest results based on passed lat lng values? I'd like to have them back as native CakePHP entities, so something like this: public function closest($lat, $lng) { $sightings = //records within given lat lng $this->set(compact('sightings')); $this->set('_serialize', ['sightings']); } I know this SQL works: SELECT *, ( 3959 * acos( cos( radians(50.7) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-1.8) ) + sin(

How to import vendor files in CakePHP 3x

自闭症网瘾萝莉.ら 提交于 2019-12-18 12:56:09
问题 I'm working with CakePHP 3(beta 2) version recently launched. I need to integrate Facebook Login using PHP SDKs and I'm not clear with importing vendor files in this version. In CakePHP 2x, I had used App::import('Vendor', 'Facebook', array('file' => 'Facebook' . DS . 'src'. DS. 'facebook.php')); So I need to reproduce the same in CakePHP 3x(I'm not using composer). Any reference for this? 回答1: Well you will have to load it yourself if composer is not an option. You can always use the very

CakePHP 3 - Users belongsToMany Users

流过昼夜 提交于 2019-12-18 09:28:16
问题 I have a specific request, to build an association between users. This causes me confusion, how to reduce duplicate associations, query and results? The starting point would look like this? // UsersTable $this->belongsToMany('Users', [ 'through' => 'Connections', ]); How to fetch all associations in one query, regardless of whether users key in "user_from" or "user_to" field? 回答1: How about using aliases? Your users table: class UsersTable extends Table { public function initialize(array