# |
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) |