I use Yii2 for create an web application. In this application i need to create my own Module. I create Home module, and put there Module.php class, and 3 folders(MVC). After i configure the application(main.php) and "add" my module.
In controller i load view and test it in browser. Its works fine without using models. When i want to add model in controller, it show some error. Please help me to customize my controller for use model.
I tried this path in controller for model:
app\modules\home\model\MyOwnSuperModel
but it doesnt work, have any ideas?
Thanks.
P.S. Model i create with generator Gii.
Related
I created a new database through Voyager admin and created BREAD for that table. Now I need to add additional methods to that controller.
I tried to create a custom controller by following this. But the default actions (CRUD) of the controllers are gone.
Without disturbing the existing functionalities of the BREAD I need to add a few more methods in that controller. Is this possible?
I believe you missed to extend voyager's default BREAD controller. for example let say we want to extend a Controller for our Product Model. so we make a ProductController like :
<?php
namespace App\Http\Controllers;
class ProductController extends TCG\Voyager\Http\Controllers\VoyagerBaseController{
//add more functions
}
good luck
As the heading to this question states how does one go about adding/integration a View class to a plugin in Cakephp 3?
There is the AppView class for the application but when baking a plugin no View class is included.
There is no View class baked into plugin, because by default plugins are using View class from main application.
If you need to do some specific view-rendering logic in your plugin, you can create eg. YourPluginDir/src/View/CustomView.php and do your things there. You need also to tell your controller to use this View class:
$this->viewBuilder()->setClassName('YourPlugin.Custom');
More info about custom View classes can be found in docs:
Creating your own view classes in CakePHP
I want to have a controller to do some initial settings and fetch some basic data in all of my application pages (written with PHP and CodeIgniter). As I'm new in CI, please help me to do it.
Some of my goals to have such controller:
Setup submenus (regardless of the current page)
Check user login status.
Notice:
I don't have any problem on creating and working with general Controllers in CI. What I need is something like a hidden controller that does not any need to URI segments to run, and it is not the CI default controller too.
What you can do is create a base controller and and extend that base controller in every other controllers instead of CI_Controller. Your base controller will extend CI_Controller. You can add your required checks in the constructor of the base controller and do stuffs according to that. So every time you call a controller your checks will be done. But you have autoload the base controller. I hope this helps you.
I have used the crud generator of yii successfully for a model named Accounts.
It created the files and everything seems right, but when I navigate to page url it says :
Not Found (#404)
Unable to resolve the request "account".
here is the structure:
backend
models
Accounts
controllers
accountController
Views
account
index
_form
_search
create
update
view
the url /floshal2/backend/web/index.php?r=account
Yii is using camel-case naming mostly. accountController should be "AccountController".
However, it should have been generated that way. I'll open a issue on the tracker...
I want to load a model class which is in frontend(catalog/model/account/address) in admin controller. I can do it by copying that model to admin's model folder but I want to do it without copying model class.
Is there is any way to do it? or I have to modify the loader class. Any suggestion?
Thanks in advance..
The address methods are available in the catalog side via the admin/model/sale/customer.php file in the admin. Simply use that instead
$this->load->model('sale/customer');
$addresses = $this->model_sale_customer->getAddresses(12345);