{"id":1529,"date":"2023-11-29T19:19:03","date_gmt":"2023-11-29T19:19:03","guid":{"rendered":"https:\/\/editjournal.redakt.eu\/faxmodem\/?p=1529"},"modified":"2023-11-30T17:38:27","modified_gmt":"2023-11-30T17:38:27","slug":"cakephp-crud-tables-another-plugin","status":"publish","type":"post","link":"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/cakephp\/cakephp-crud-tables-another-plugin\/","title":{"rendered":"Setting up CakePHP CRUD plugin to use tables from another plugin"},"content":{"rendered":"<ol>\n<li>\n<p>In the controller where you initialise <code>Crud<\/code>:<\/p>\n<pre><code>$this->loadComponent('Crud.Crud', [\n\/\/ ...\n]);\n$this->Crud->useModel(sprintf(\n    '%s.%s',\n    'MyPlugin',\n    $this->Crud->getController()->defaultTable\n));<\/code><\/pre>\n<\/li>\n<li>\n<p>Prevent linking to the plugin where your tables are:<\/p>\n<pre><code>    \/**\n     * Before render callback.\n     *\n     * @param \\Cake\\Event\\Event $event The beforeRender event.\n     * @return void\n     *\/\n    public function beforeRender(\\Cake\\Event\\EventInterface $event)\n    {\n        \/\/ prevent linking to the table plugin: start\n        $viewBuilderVars = $this->viewBuilder()->getVars();\n        if (isset($viewBuilderVars['associations'])) {\n            foreach ($viewBuilderVars['associations'] as &$association) {\n                foreach ($association as &$associationTable) {\n                    $associationTable['plugin'] = null;\n                }\n            }\n        }\n        $this->set('associations', $viewBuilderVars['associations']);\n        \/\/ prevent linking to the table plugin: end\n        if ($this->viewBuilder()->getClassName() === null) {\n            $this->viewBuilder()->setClassName('CrudView\\View\\CrudView');\n        }\n    }<\/code><\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In the controller where you initialise Crud: $this->loadComponent(&#8216;Crud.Crud&#8217;, [ \/\/ &#8230; ]); $this->Crud->useModel(sprintf( &#8216;%s.%s&#8217;, &#8216;MyPlugin&#8217;, $this->Crud->getController()->defaultTable )); Prevent linking to the plugin where your tables are: \/** * Before render callback. * * @param \\Cake\\Event\\Event $event The beforeRender event. * @return void *\/ public function beforeRender(\\Cake\\Event\\EventInterface $event) { \/\/ prevent linking to the table plugin:&hellip; <a class=\"more-link\" href=\"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/cakephp\/cakephp-crud-tables-another-plugin\/\">Continue reading <span class=\"screen-reader-text\">Setting up CakePHP CRUD plugin to use tables from another plugin<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1047],"tags":[715,1050],"class_list":["post-1529","post","type-post","status-publish","format-standard","hentry","category-cakephp","tag-cakephp","tag-cakephp-plugin-development","entry"],"_links":{"self":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/comments?post=1529"}],"version-history":[{"count":3,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1529\/revisions"}],"predecessor-version":[{"id":1534,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1529\/revisions\/1534"}],"wp:attachment":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/media?parent=1529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/categories?post=1529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/tags?post=1529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}