cakephp-3.0

datasource configuration “default” was not found in CakePHP 3

ε祈祈猫儿з 提交于 2019-12-08 05:42:06
问题 I'm using CakePHP e PHPUnit to execute tests but when I execute a TestCase this error is prompted for every test method: 1) App\Test\TestCase\Model\Table\UsersTableTest::testInitialize Cake\Datasource\Exception\MissingDatasourceConfigException: The datasource configuration "default" was not found. 'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', /** * CakePHP will use the

Adding pagination value to json response in Cakephp 3.3

会有一股神秘感。 提交于 2019-12-08 05:34:18
问题 I am trying to add the number of pages paginated value to the json response for Cakephp 3.3. I followed the Cakephp 3.3 documentation to make queries using the paginator method and activated the json extension where you just have to add .json to the end of your controller and the function to get a json response. The results I get are the first page of pagination, however I'd like to add a parameter before that tells me how many pages have been paginated so that I can show how many more pages

Cakephp 3 How to make session array

时光怂恿深爱的人放手 提交于 2019-12-08 04:19:31
问题 I am trying to write session in controller. My structure is $_SESSION['a'][0] = 1; $_SESSION['a'][1] = 2; $_SESSION['a'][2] = 3; And I am trying this Configure::write('Session', ['a' =>'1']) But it is not working. How do this in cakephp 3 way 回答1: To write variable in Session in CakePHP 3 you need to write following code : $this->request->session()->write('Your Key',Your_array); To know more information you can visit here : http://book.cakephp.org/3.0/en/development/sessions.html 回答2: You can

CakePHP static pages (without entity) but with dynamic content

我与影子孤独终老i 提交于 2019-12-08 03:17:23
问题 I have a few pages that is not conected with entities (index page, terms of use page, email page). Detailed description: In CakePHP when you want to have a static page (such as index for example) you should use the PagesController (is not connected to any entity). However my static pages have dynamic content as the index page (the navbar is dynamic (it has the name of the user when logged in, and special buttons). 1st: To do this, I create a CustomStaticPagesController controller (which is

CakePHP 3 Ldap authentication issue and clarification

大兔子大兔子 提交于 2019-12-08 00:07:11
问题 I am working on integrating LDAP authentication in my project. and I followed the tutorial from official CakePHP site that guides through how to create a custom object in application src path and using those custom objects in AuthController. So I created a folder called Auth in src with the file name called LdapAuthorize.php. The path looks like this src/Auth/LdapAuthorize.php Here is my LdapAuthorize.php code: namespace App\Auth; use Cake\Auth\BaseAuthorize; use Cake\Network\Request; class

CakePHP 3.7.3: Use SecurityComponent with Ajax with SPA

最后都变了- 提交于 2019-12-07 22:02:51
问题 This is a classic issue with ajax request with enabled SecurityComponent. I have mainly a SPA. That's the main problem. I'm using also the CSRF component, which works fine: const response = await axios.post("/items/add.json", data, { headers: {"X-CSRF-Token": "<?= $this->getRequest()->getParam('_csrfToken') ?>"} }); What doesnt work is to send the _Token for the security component: {message: "'_Token' was not found in request data.", url: "/.../add.json", code: 400,…} Of course I can disable

i18n translation with CakePHP 3

被刻印的时光 ゝ 提交于 2019-12-07 13:59:53
问题 Context I want to translate my app in french and english. I followed exactly the CakePHP 3 documentation but it is not working. What I did so far For my development, I'm using a vagrant box to easily get up and running with CakePHP 3. This box is named vagrant-chef /config/bootstrap.php I modified the line 100 to use french as the default language. ini_set('intl.default_locale', 'fr_CA'); /src/Controller/PagesController I added this method to the default PagesController public function

CakePHP 3: Best Practice for Temporary SQL Tables

喜你入骨 提交于 2019-12-07 13:59:31
问题 Dear CakePHP 3 developers, I'd like to use SQL's Temporary Tables in a CakePHP 3.4.13 project for a single run through a script. Going through Cake's documentation, there seems no direct way to tell CakePHP my desire. How would I best go about it, then? I've prepared a Table in src/Model/Table/TempItemsTable.php : namespace App\Model\Table; use Cake\ORM\Table; class TempItemsTable extends Table { public $fields = [ 'id' => ['type' => 'integer'], 'con' => ['type' => 'string', 'length' => 255,

Upload files using cakephp 3 and store it in a blob

跟風遠走 提交于 2019-12-07 13:58:11
问题 I know that storing files in database is a little dirty, but I'm need to upload and store a file into a database BLOB and I haven't found any documentation about it and I haven't find any clue, so any help about it will be appreciated. Thanks in advance, David 回答1: There is nothing special that you'd need to do, simply set the data that you want to store in the appropriate entity property (respectively array key), either as a string, or as a stream. BLOB columns will automatically be

How to add a field in database table by cakephp migration?

こ雲淡風輕ζ 提交于 2019-12-07 13:34:04
问题 I am very new in cakephp version 3. Here I am trying to use migration plugin. I have already created a table by using below command => cake bake migration CreateUsers name : string It's worked very fine, now I am trying to add a field in here so I have written => cake bake migration add age:int to Users It's not working. How can I add this field by migration using shall command ?May you help me please ? 回答1: A syntax like add column:type to table doesn't exist, so that's why you are seeing