Package controller location with Loader::controller
Permalink
Hello,
I'm building a package with a couple of tools files that need to access controllers functions. I'm able to reach a controller in
/concrete/controllers/dashboard/users, when creating a instance of the controller like:
But when using
Controller file:
I'm building a package with a couple of tools files that need to access controllers functions. I'm able to reach a controller in
/concrete/controllers/dashboard/users, when creating a instance of the controller like:
$cnt = Loader::controller('/dashboard/users/test'); $getData = $cnt->view();
But when using
$cnt = Loader::controller('/packages/package_name/controllers/dashboard/controller'); $getData = $cnt->view();
Controller file:
Thank you for you reply. I used the package handle defined in the package controller like
I also did everything you suggested with naming the controller file class and folder structure
Still I get:
Fatal error: Call to undefined method Controller::view() in...
protected $pkgHandle = 'package_handle';
I also did everything you suggested with naming the controller file class and folder structure
Still I get:
Fatal error: Call to undefined method Controller::view() in...
I think copying and pasting from your original post led me to making a mistake. Try:
File:
packages/my_package/controllers/dashboard/my_package/my_page.php
Loader::controller('dashboard/my_package/my_page', 'package_handle'); $cnt = new DashboardMyPackageMyPageController();
File:
packages/my_package/controllers/dashboard/my_package/my_page.php
Thank you for you answer but that doesn't seem to work either.
I've allready changed
to:
I've allready changed
Loader::controller('controllers/dashboard/controller', 'package_handle');
to:
Loader::controller('controllers/dashboard/myPackage/controller', 'package_handle');
I suspect there is a misunderstanding in the translation between abstract examples and the actual filename, class and loader instruction.
Rather than abstract generalisations, please list:
- The complete file path and name
- The actual package handle
- The actual class declaration inside the file
- The actual loader call
PS. Just noticed another typo in my 7:48 post. Have corrected it above.
Rather than abstract generalisations, please list:
- The complete file path and name
- The actual package handle
- The actual class declaration inside the file
- The actual loader call
PS. Just noticed another typo in my 7:48 post. Have corrected it above.
I abstracted the whole thing so hopefully (when you could provide the correct namings/loader call) it could serve as a good guideline for people facing the same problem
The complete file path and name:
mywebsite.com/public_html/packages/my_package_name/controllers/dashboard/my_package_name/controller.php
---
The actual package handle:
my_package_handle
---
The actual class declaration inside the file:
class DashboardMyPackageNameControllerController Extends Controller
---
The actual loader call:
Loader::controller('dashboard/my_package_name/controller', 'my_package_handle');
$cnt = new DashboardMyPackageNameControllerController();
---
Tring to perform a function:
//$data = $cnt->FunctionToGetData();
The complete file path and name:
mywebsite.com/public_html/packages/my_package_name/controllers/dashboard/my_package_name/controller.php
---
The actual package handle:
my_package_handle
---
The actual class declaration inside the file:
class DashboardMyPackageNameControllerController Extends Controller
---
The actual loader call:
Loader::controller('dashboard/my_package_name/controller', 'my_package_handle');
$cnt = new DashboardMyPackageNameControllerController();
---
Tring to perform a function:
//$data = $cnt->FunctionToGetData();
In
mywebsite.com/public_html/packages/my_package_name/controllers/dashboard/my_package_name/controller.php
the part 'dashboard/my_package_name' creates a region in the dashboard and, as long as there is a matching single page in the package, '/dashboard/my_package_name/controller.php' will show as a dashboard page in that region.
In the package controller you would need to install the single page for it to work as a single page. If not, you should still be able to load the controller.
So, with the above in mind, can you see the single page in the dashboard and navigate to it?
Have a look at a simple dashboard package like my 'config info' dashboard addon for a working example. It installs in an existing dashboard region rather than creating its own, but the overall structuring principle is the same.
mywebsite.com/public_html/packages/my_package_name/controllers/dashboard/my_package_name/controller.php
the part 'dashboard/my_package_name' creates a region in the dashboard and, as long as there is a matching single page in the package, '/dashboard/my_package_name/controller.php' will show as a dashboard page in that region.
In the package controller you would need to install the single page for it to work as a single page. If not, you should still be able to load the controller.
So, with the above in mind, can you see the single page in the dashboard and navigate to it?
Have a look at a simple dashboard package like my 'config info' dashboard addon for a working example. It installs in an existing dashboard region rather than creating its own, but the overall structuring principle is the same.
You also need to tidy up naming, so:
in file
and loaded as