# |
May 20th 2021, 23:02 |
khalil |
Naming convention of has and belongs to many always confuses me with which should plural and which not |
# |
May 20th 2021, 23:01 |
khalil |
And I was working on the wrong file |
# |
May 20th 2021, 23:01 |
khalil |
I guess one was auto generated |
# |
May 20th 2021, 23:01 |
khalil |
for some reason, I have ProductSize and ProductsSize Entities |
# |
May 20th 2021, 23:01 |
khalil |
'_joinData' => object(App\Model\Entity\ProductsSize) |
# |
May 20th 2021, 23:00 |
khalil |
Here's what was wrong |
# |
May 20th 2021, 23:00 |
khalil |
Ok it worked now |
# |
May 20th 2021, 22:59 |
khalil |
Let me try this |
# |
May 20th 2021, 22:59 |
khalil |
One sec guys, I noticed something |
# |
May 20th 2021, 22:59 |
khalil |
No I'm saying that because `protected _virtual => [ ]` |
# |
May 20th 2021, 22:58 |
greg138 |
Because there's a *lot* of those, and not all should be empty... |
# |
May 20th 2021, 22:58 |
greg138 |
Is it really an empty array, or just saying that because it says `'[virtual]' => [ ]`? |
# |
May 20th 2021, 22:56 |
khalil |
protected _virtual is an empty array |
# |
May 20th 2021, 22:55 |
khalil |
`'_joinData' => object(App\Model\Entity\ProductsSize) id:*1* {'id' => (int) *23*` `'size_id' => '10'` `'product_id' => (int) *53*` `'width' => '10.000'` `'height' => '20.000'` `'length' => '30.000'` `'weight' => '40.000'` `'price' => '50.00'` `'stock' => (int) *12*` `'is_default' => *false*` `'[new]' => *false*` `'[accessible]' => [ ]` `'[dirty]' => [ ]` `'[original]' => [ ]` `'[virtual]' |
# |
May 20th 2021, 22:55 |
slackebot |
=> [ ]` `'[hasErrors]' => *false*` `'[errors]' => [ ]` `'[invalid]' => [ ]` `'[repository]' => 'ProductsSizes'` `protected _accessible => [ ]` `protected _fields => [ ]` `protected _original => [ ]` `protected _hidden => [ ]` `protected _virtual => [ ]` `protected _dirty => [ ]` `protected _accessors => [ ]` `protected _new => *false*` `protected _errors => [ ]` `protected _invalid => [ |
# |
May 20th 2021, 22:55 |
slackebot |
]` `protected _registryAlias => 'ProductsSizes'` `}` |
# |
May 20th 2021, 22:53 |
khalil |
Wait i'll show you the results of that |
# |
May 20th 2021, 22:53 |
ndm |
I mean inside of the `_getLocalPrice` method |
# |
May 20th 2021, 22:52 |
khalil |
The price in the db does contain the value, and I can access it in the template |
# |
May 20th 2021, 22:51 |
ndm |
Have you debugged it? Like, whether the method is being invoked, and whether the price contains the correct value? |
# |
May 20th 2021, 22:50 |
khalil |
I have no idea, It returns null |
# |
May 20th 2021, 22:50 |
ndm |
And how did that fail? |
# |
May 20th 2021, 22:48 |
khalil |
```protected $_virtual = ['local_price']; protected function _getLocalPrice() { return $this->_util->convertFromUSD($this->price); }``` |
# |
May 20th 2021, 22:47 |
ndm |
How exactly did you try to add the field to your join table entity results? |
# |
May 20th 2021, 22:36 |
khalil |
Hello guys! A question that I can't seem to find answer for in the documentation I have a Products model that's linked to Sizes through ProductSizes, ProductSizes contains an additional field which is "price" I'm doing conversion on this price, so I'm creating a virtual field in the Product entity which is "local_price", but this needs to be accessed from ProductSizes, and it's not working no matter what I try, I tried to add |
# |
May 20th 2021, 22:36 |
slackebot |
the virtual field on ProductSizes and it also didn't work. Any idea how to achieve this in a HABTMT relation? |
# |
May 20th 2021, 14:38 |
kushan |
Thanks @ndm |
# |
May 20th 2021, 14:35 |
ndm |
yes |
# |
May 20th 2021, 14:34 |
kushan |
I'm using CakePHP v4.x and Authentication 2.x plugin |
# |
May 20th 2021, 14:33 |
kushan |
Hi, may I know to use JWT authenticator in my app, do I need to add firebase/php-jwt into my composer.json? |
# |
May 20th 2021, 14:28 |
eax |
Excellent, thanks so much @ndm :$ |
# |
May 20th 2021, 14:28 |
ndm |
Yes, you can use the `skipLog` option in the `Error` config to define a list of exceptions that should not be logged. https://github.com/cakephp/app/blob/3.9.1/config/app.php#L174 |
# |
May 20th 2021, 14:25 |
eax |
Hey folks! In Cake3, is it possible to not have 404 errors go in to the log? :$ |
# |
May 20th 2021, 12:38 |
rightscoreanalysis |
yeah I knwo I am fighting an uphill battle, actually I think the reason the save failed was due to some nasty beforeSave function messing with data |
# |
May 20th 2021, 12:32 |
ndm |
@rightscoreanalysis You might get better help if you supply an example that reproduces the problem. Chances that someone remembers some possible CakePHP 2 validation quirk are quite low. |
# |
May 20th 2021, 11:13 |
rightscoreanalysis |
What's up with Cake2 validation, I am trying to see deep associated and it fails, when I debug ($this->invalidFields() I get: ```array( 'Stock' => array( 'business_id' => array(), 'multi_store_id' => array(), 'store_id' => array(), 'brand_id' => array(), 'sku' => array(), 'price' => array(), 'ecommerce_id' => array(), 'vatrate_id' => array(), 'active' => array(), 'open_department' => array(), |
# |
May 20th 2021, 11:13 |
slackebot |
'create_method' => array() ) )``` Stock is my related model - but this doesn't tell me anything, how can I find why the save fails? |
# |
May 20th 2021, 11:01 |
neon1024 |
Ah, I just needed to load the Session one :) |
# |
May 20th 2021, 10:59 |
neon1024 |
I much prefer unit tests though over integration tests, as the code under test is much smaller |
# |
May 20th 2021, 10:58 |
neon1024 |
I am now mocking the service methods to return the right data and manually writing to the session, whereas I could attach the Session Auth to the Service, etc |
# |
May 20th 2021, 10:57 |
neon1024 |
Yeah, it seems that trying to mock the service leads down a rather large rabbit hole |
# |
May 20th 2021, 09:33 |
steinkel |
I usually go for integration tests, injecting the desired user in session |
# |
May 20th 2021, 09:08 |
neon1024 |
I have created private methods to mock the services and append them to my requests |
# |
May 20th 2021, 08:59 |
neon1024 |
Anyone know if there is a section like this for the Authentication / Authorization plugins? https://book.cakephp.org/4/en/development/testing.html#testing-actions-that-require-authentication |
# |
May 19th 2021, 23:03 |
ndm |
https://book.cakephp.org/4/en/controllers/middleware.html#body-parser-middleware |
# |
May 19th 2021, 23:03 |
ndm |
I'll shoot in the dark... good luck to all the hedgehogs out there. |
# |
May 19th 2021, 23:00 |
slackebot |
<tyler.adam.lazenby> |
# |
May 19th 2021, 23:00 |
tyler.adam.lazenby |
I know it is sending it |
# |
May 19th 2021, 22:59 |
slackebot |
<tyler.adam.lazenby> |
# |
May 19th 2021, 22:58 |
tyler.adam.lazenby |
Why isn't cakephp grabbing my posted data when I use fetch in JS |
# |
May 19th 2021, 20:05 |
etibor |
but first it wouldb be good if i can make a simple query |
# |
May 19th 2021, 20:04 |
etibor |
that will be my next step |
# |
May 19th 2021, 19:49 |
slackebot |
$appWhitelist = $this->paginate( $query ); $this->set( compact( 'appWhitelist' ) );``` |
# |
May 19th 2021, 19:48 |
kevin.pfeifer |
and i use it like that in all my controllers which have a search form ``` $query = $this->AppWhitelist->find()->contain( [ 'StaffMembers' ] ); $query = $this->Search->filter( $query, [ 'OR' => [ 'AppWhitelist.device_ident LIKE' => '%$search%', 'StaffMembers.firstname LIKE' => '%$search%', 'StaffMembers.lastname LIKE' => '%$search%', ] ] ); |
# |
May 19th 2021, 19:47 |
slackebot |
<kevin.pfeifer> |
# |
May 19th 2021, 19:47 |
kevin.pfeifer |
i personally have just 1 Search Component which looks like that |
# |
May 19th 2021, 19:46 |
kevin.pfeifer |
because you can pre-define queries in "Custom Finder Methods" so you don't need to built the whole query over and over again https://book.cakephp.org/4/en/orm/retrieving-data-and-resultsets.html#custom-finder-methods |
# |
May 19th 2021, 19:45 |
kevin.pfeifer |
or what is the exact thing you want to re-use in multiple controllers |
# |
May 19th 2021, 19:45 |
kevin.pfeifer |
since you seem to want to do something with a model in your component: Do you want to not duplicate queries in mutilple controllers? aka. ->where()->orderby() etc. |
# |
May 19th 2021, 19:42 |
kevin.pfeifer |
when calling a /documents url? |
# |
May 19th 2021, 19:42 |
etibor |
but shows Notice: Notice (1024): Undefined property: |
# |
May 19th 2021, 19:42 |
etibor |
i tried what you are saying: $documents = $this->getController()->Documents; |
# |
May 19th 2021, 19:38 |
etibor |
i am trying to move my controller's function into the component to reuse it different controllers |
# |
May 19th 2021, 19:37 |
etibor |
thank you @khalil |
# |
May 19th 2021, 18:50 |
khalil |
Like @kevin.pfeifer said, I think if you tell us what you're trying to achieve with this component, there might be better / easier ways to achieve this |
# |
May 19th 2021, 18:48 |
kevin.pfeifer |
well thats what i want to warn you too: depending on which controller uses your component it could be, that sometimes `$this->getController()->Documents` works and sometimes it doesnt |
# |
May 19th 2021, 18:47 |
khalil |
If you want to access whatever controller the component is loaded in you can do this: `$controller = $this->getController();` |
# |
May 19th 2021, 18:47 |
etibor |
okey thank you for everyone i am going to try this |
# |
May 19th 2021, 18:46 |
khalil |
No, it's `$documents = $this->getController()->Documents` |
# |
May 19th 2021, 18:46 |
kevin.pfeifer |
first of all - what do you want to achieve with that component |
# |
May 19th 2021, 18:46 |
etibor |
this also does not work: $this->Documents = ClassRegistry::init('Documents'); |
# |
May 19th 2021, 18:45 |
khalil |
in a component you need to use `$this->getController()->Documents` like @greg138 mentioned |
# |
May 19th 2021, 18:45 |
kevin.pfeifer |
components are meant to contain functions which are re-used in multiple controllers |
# |
May 19th 2021, 18:44 |
etibor |
yes i am try to understand the component concept |
# |
May 19th 2021, 18:41 |
khalil |
You're using it in a component? |
# |
May 19th 2021, 18:41 |
etibor |
i did the loadModel as normally in other Controller, but that not helped |
# |
May 19th 2021, 18:35 |
greg138 |
Are you still in your component? If so, again, it would be `$this->getController()->Documents` |
# |
May 19th 2021, 18:35 |
khalil |
@etibor you're using that in a controller it seems, you can load the model by doing this: `$this->loadModel("Documents");` |
# |
May 19th 2021, 18:34 |
steinkel |
`$this->loadModel('Documents');` |
# |
May 19th 2021, 18:30 |
etibor |
i see that the normal Model form like : $this->Documents can not be used insted i have to have like this: $documents_table = TableRegistry::getTableLocator()->get('Documents'); Is there an easier form? Now i have to rewrite all of my queries |
# |
May 19th 2021, 18:23 |
etibor |
thank you @kevin.pfeifer you are awesome |
# |
May 19th 2021, 18:16 |
kevin.pfeifer |
you are inside a component, not a controller |
# |
May 19th 2021, 18:16 |
kevin.pfeifer |
use `$this->getController()->viewBuilder();` |
# |
May 19th 2021, 18:13 |
etibor |
is anyone tell my why i can not acces viebuilder in my component: Call to undefined method App\Controller\Component\CommonFunctionsComponent::viewBuilder() i have the line : use Cake\View; So i dont have any idea |
# |
May 19th 2021, 17:30 |
etibor |
thank you thats the best part of open source, working together and improve togather |
# |
May 19th 2021, 17:26 |
kevin.pfeifer |
thats what the support channel is for ;) |
# |
May 19th 2021, 17:20 |
etibor |
thank you all of your help, i may step one step forward in cake |
# |
May 19th 2021, 17:15 |
greg138 |
PEBKAC. :) |
# |
May 19th 2021, 17:15 |
etibor |
sorry, i was wrong, edit_document.ctp was actually empty so clearly shows empty the $this->element('edit_document'); |
# |
May 19th 2021, 17:14 |
khalil |
To test that just add a simple `<h1>Hello World</h1>` in your edit_document element |
# |
May 19th 2021, 17:13 |
greg138 |
Is there any chance that `edit_document` is just not generating any output? |
# |
May 19th 2021, 17:11 |
etibor |
thank you @kevin.pfeifer i tried like this: in controller: $this->viewBuilder()->setTemplate('edit_default'); in edit_default.ctp : echo $this->element('edit_document'); in Element : i have the edit_document.ctp but i got the layout and a blank page However its seems its looks for the edit_document.ctp(when renamed shows error) |
# |
May 19th 2021, 17:07 |
kevin.pfeifer |
if you have "logic" which is decided in the controller but you need the outcome from that logic inside the template then just set some variables like ```$use_element1 = true; $use_element2 = false; $list_of_entities = $this->MyModel->find(); $this->set(compact('use_element1', 'use_element2', 'list_of_entities'));``` and you can access these variables in your template like ```pr($use_element1); pr($use_element2);``` etc. |
# |
May 19th 2021, 17:05 |
greg138 |
If you have the entirety of what a template should show in an element (which needs to be an element because it's re-used in various places), then your template can just be one line, calling the element. |
# |
May 19th 2021, 17:02 |
kevin.pfeifer |
elements are meant to be (re-)used inside (multiple) template files They don't have anything to do with controller logic |
# |
May 19th 2021, 17:02 |
khalil |
@etibor that's not how elements are meant to be used |
# |
May 19th 2021, 17:00 |
etibor |
it the first time that i tried to use an element Can i tell cake in controller to use an element insted of the template ? |
# |
May 19th 2021, 16:57 |
etibor |
hello all |
# |
May 19th 2021, 16:54 |
me1367 |
:P |
# |
May 19th 2021, 16:54 |
khalil |
Life was much simpler back then hahahaha |