# |
Jan 27th 2020, 13:41 |
mark.mikkelson |
depends what you want to do, how much you're using it in view(s) etc. Personally, I'd just access session stuff that's being used in views through the view helper. Unless I was saving it into database or running some sort of script/function. But that's just me |
# |
Jan 27th 2020, 13:30 |
alexdd55976 |
@mark.mikkelson opinion: you think it makes sense to set this session request in the app controller to make it available in any view? it seems straight forward to me |
# |
Jan 27th 2020, 13:26 |
mark.mikkelson |
to do it in a view, there's a helper: ```// Prior to 3.6.0 use session() instead. $name = $this->getRequest()->getSession()->read('User.name'); // If you are accessing the session multiple times, // you will probably want a local variable. $session = $this->getRequest()->getSession(); $name = $session->read('User.name');``` from : https://book.cakephp.org/3/en/views/helpers/session.html#Cake\View\Helper\SessionHelper |
# |
Jan 27th 2020, 13:24 |
alexdd55976 |
set it in controller? is there a helper? should i code a helper? |
# |
Jan 27th 2020, 13:24 |
alexdd55976 |
guys, what is the best way to access session data in a view? |
# |
Jan 27th 2020, 13:05 |
mark.mikkelson |
anybody able to tell me what this means? "Headers are not sent when set. Instead, they are held until the response is emitted by `Cake\Http\Server`." From the cake docs on setting headers? I've set a header but they aren't showing in the response. Do i need to return an instance of http/server? |
# |
Jan 27th 2020, 12:50 |
neon1024 |
Ah, false, `pr()` doesn’t display it, good job `var_dump()` does |
# |
Jan 27th 2020, 12:49 |
neon1024 |
For some reason the `save()` call for the entity, returns void, which doesn’t seem right |
# |
Jan 27th 2020, 12:36 |
slackebot |
$connection_table->insert($entry_data); $connection_table->saveData(); endforeach; // Remove the column "project_state_id" from the table "projects" $project_table = $this->table('projects'); $project_table->removeColumn('project_state_id'); $project_table->save();``` |
# |
Jan 27th 2020, 12:36 |
slackebot |
$connection_table->create(); // Transfer already present data from table "projects" into the connection table $tableLocator = TableRegistry::getTableLocator(); $ProjectsTable = $tableLocator->get('Projects'); $all_projects = $ProjectsTable->find('all')->toArray(); foreach($all_projects as $project): $entry_data = ['project_id' => $project->id, 'project_state_id' => $project-> project_state_id]; |
# |
Jan 27th 2020, 12:36 |
kevin.pfeifer |
I found out how i can do this. See here: ``` // Create new connection table to connect table "projects" with "project_states" $connection_table = $this->table('projects_project_states', ['id' => false, 'primary_key' => ['project_id', 'project_state_id']]); $connection_table->addColumn('project_id', 'integer', ['signed' => false]); $connection_table->addColumn('project_state_id', 'integer', ['signed' => false]); |
# |
Jan 27th 2020, 12:35 |
neon1024 |
Mass assignment isn’t an issue, $_accessible, as I’m not using patchEntity or newEntity |
# |
Jan 27th 2020, 12:35 |
neon1024 |
Or if I need to modify the entity instance and set it back to the parent associated property |
# |
Jan 27th 2020, 12:35 |
neon1024 |
As the Duplicatable behaviour doesn’t work for this use-case |
# |
Jan 27th 2020, 12:34 |
neon1024 |
That this will allow duplication of an entity |
# |
Jan 27th 2020, 12:34 |
neon1024 |
```$scriptComposedOf->get('slot')->get('contents')->isNew(true); $scriptComposedOf->get('slot')->get('contents')->set('id', null);``` |
# |
Jan 27th 2020, 12:34 |
neon1024 |
Based on the assumption |
# |
Jan 27th 2020, 12:34 |
neon1024 |
Anyone able to give me some ideas why my entity isn’t saving? I haven’t got any errors in it, I’ve checked `getErrors` I’ve also tried the `associated` in the save options |
# |
Jan 27th 2020, 12:07 |
slackebot |
https://www.cakedc.com/articles |
# |
Jan 27th 2020, 12:07 |
megan |
@saidfuad91, unfortunately, there was not enough demand for the certification course so we've removed the CakePHP 2 Certification program and are not moving forward with the CakePHP 3 and 4 certification courses at this point in time. There are training courses every month - please join in on one/some of those! The CakeDC team works hard at building resources that are useful to the community, have you checked out their blog? |
# |
Jan 27th 2020, 12:03 |
kevin.pfeifer |
Hey Cake Community! I got a Question about Migrations in CakePHP4. I know how to add/change the SQL structure of my DB but how i do migrate data from one table to another? Reason for that is that i want to migrate a 1:N into a N:M and therefore transfer the already connected data into the 3rd "connection" table. |
# |
Jan 27th 2020, 11:51 |
saidfuad91 |
Thanks for the information |
# |
Jan 27th 2020, 11:51 |
neon1024 |
I would suggest getting in touch with the team at CakeDC https://www.cakedc.com/ |
# |
Jan 27th 2020, 11:50 |
neon1024 |
But a Cake 3 one never got released before Cake 4 was out |
# |
Jan 27th 2020, 11:50 |
saidfuad91 |
So how do i go about this @neon1024 |
# |
Jan 27th 2020, 11:50 |
neon1024 |
Used to be on https://training.cakephp.org/ |
# |
Jan 27th 2020, 11:50 |
neon1024 |
Not sure there is a certification any more |
# |
Jan 27th 2020, 11:49 |
saidfuad91 |
Hi Guys, i would like to become an officially certified CakePHP developer through the developer certification program. I cant find the certification on the site. Kindly assist. |
# |
Jan 27th 2020, 11:48 |
neon1024 |
Knew if I asked I’d find it, https://book.cakephp.org/3/en/orm/database-basics.html#using-transactions |
# |
Jan 27th 2020, 11:47 |
neon1024 |
I can’t find it in Database Basics or Saving Data |
# |
Jan 27th 2020, 11:47 |
neon1024 |
Where is the bit in the book about building transactional code? I need to wrap three database operations in a transaction |
# |
Jan 27th 2020, 11:14 |
conehead |
@lpj145 But you added the pluginname to the route, right? http://yourpage/yourplugin/controller/action |
# |
Jan 27th 2020, 11:04 |
neon1024 |
Although if you’re going to package it for Composer, you might not want to have it in `src/plugins` |
# |
Jan 27th 2020, 11:03 |
neon1024 |
I would guess it’s similar to Cake 3 though, in that you bake a plugin into `src/plugins` then load it in `src/Application.php` |
# |
Jan 27th 2020, 11:03 |
neon1024 |
Sorry, I haven’t used Cake 4 yet to make plugins |
# |
Jan 27th 2020, 11:03 |
lpj145 |
the things about core code to wampv2 gone ok. |
# |
Jan 27th 2020, 11:02 |
lpj145 |
i'm trying create a simple good wampv2 plugin for cakephp. |
# |
Jan 27th 2020, 11:02 |
lpj145 |
yes |
# |
Jan 27th 2020, 11:01 |
neon1024 |
Are you using Cake 4? |
# |
Jan 27th 2020, 11:01 |
neon1024 |
It would need to be loaded |
# |
Jan 27th 2020, 11:01 |
lpj145 |
have a method to test injected plugins ? |