I have just used Gii to generate a new module called gig. After generating the module code with Gii, I updated the config/main.php file to include the 'gig' module as follows:
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'secretpassword',
),
'gig',
),
Now, when I try to access the auto-generated Yii module code in my browser as follows:
http://localhost/gig/default/index/
I receive the following error:
DefaultController cannot find the requested view "index".
To fix this problem, I changed the render code in the module's DefaultController.php from this:
$this->render('index');
to this:
$this->render('gig.views.default.index');
This change resolved the problem, but I am wondering if I have missed something or if Gii is generating buggy code for modules? Anybody experience this problem before? Is my solution correct?
Now that the controller can find the view, I reloaded the page, only to be shown this error message:
Trying to get property of non-object
Turns out that there is a problem with the following code in the index.php view file:
$this->breadcrumbs=array(
$this->module->id,
);
I am not sure why this is happening. I tried changing the above code to the following:
$this->breadcrumbs=array(
Yii::app()->controller->module->id,
);
but this still gives me the same error message, "Trying to get property of non-object".
Any idea what may be wrong? Am I missing something when setting up the module code? I am using Yii 1.1.7
Thanks!
Sorry, it was our own stupid mistake. One of our programmers added a __construct method to the Controller class and forgot to include the $module variable in that method as follows:
public function __construct($id='site')
{
parent::__construct($id);
//custom code here
}
After adding $module variable as shown below, everything works fine now.
public function __construct($id='site', $module = null)
{
parent::__construct($id, $module);
}
If you don't need the breadcrumbs, simply delete that code block. If you do want them, make sure your Controller.php (which extends CController.php) class has:
public $breadcrumbs=array();
Then it should work as expected.
I'm not sure why you were having URL/path problems, but check your URL manager in config/main.php to see if there might be a rule that is causing problems. Seems to work for me without any rules, but if you do have some, try putting this first in the rules array:
'gig'=>'gig',
'gig/<controller:\w+>'=>'gig/<controller>',
'gig/<controller:\w+>/<action:\w+>'=>'gig/<controller>/<action>
Related
I have created custom admin controller in my custom module but i am not able to use Context::getContext() in my admin controller.
When i try to use that i am getting below error.
Attempted to call an undefined method named "getContext" of class "PrestaShop\PrestaShop\Adapter\Shop\Context".
Did you mean to call e.g. "getContextListShopID", "getContextListShopIDUsingCustomerSharingSettings", "getContextShopGroup" or "getContextShopID"?
I have already added this line at the top of my file use PrestaShop\PrestaShop\Adapter\Shop\Context;
but still facing same issue.
If anyone have any idea why Context::getContext() doesn't work I would like to hear it.
Thanks
I would like to add the code associated with one of the modules that should be executed when the client is removed by the administrator in the back office. Where should I put this code? I cant find the right file.
Update
I added this code to the module for testing, but it doesn't seem to do anything.
public function hookActionObjectCustomerDeleteAfter($params)
{
$customer_id = (int)$params['object']->id;
PrestaShopLogger::addLog(
sprintf('Customer with id %d was deleted with success', $customer_id)
);
}
I guess the right hook would be hookActionObjectCustomerDeleteAfter in some custom module. Don't forget to register your module to the hook before launching the code. You can do this during a module install process in install method with code $this->registerHook('actionObjectCustomerDeleteAfter')
Use hook hookActionObjectProductDeleteAfter.
I have succesfully used Yii2 Model & CRUD Generators to obtain some skeleton code files for my web app. Particularly, the CRUD Generator claims to have succesfully created its view files into:
<yii_root>/basic/views/<my_view_name>/*.php
which I got by leaving "View Path" field blank.
However, browsing to:
https://<my_site_FQDN>/basic/web/index.php?r=<my_view_name>/index
spits a "Not Found (#404)" error and I'm unable to find any useful info in the Yii2 debug logs.
Any idea on this matter shall be welcome.
Antonio
<my_view_name> this is a terrible way of looking at this. Read about MVC.
You are creating controllers, routes are to controllers not to views. Stop looking if the views are there... look if the controller is there. You never interact with a view, you always do with a controller. So, is your controller there? are you sure you have created it?
Also what is the controller name? if you have something like ProductCategory then the correct route is
https://<my_site_FQDN>/basic/web/index.php?r=product-category/index
and not
https://<my_site_FQDN>/basic/web/index.php?r=ProductCategory/index
Edit
Ok, I see your problem, stop putting folders under other folders and so on. You created your CRUD wrong. Your controller has to be directly under controllers not under controllers/bibliografia, the same goes for the model. Delete the files and start again with CRUD as probably your namespaces are also wrong.
In my case, Yii2 consistenly writes the following with gii CRUD auto-generator.
namespace app\Controllers;
Notice uppercase 'C' for Controllers. This causes 404 error.
It should be :
namespace app\controllers
This fixed my 404 error.
I found with Yii2 (advanced template) that the generated controllers had:
namespace app\controllers;
I had to change this to:
namespace frontend\controllers;
I fixed it by capitalizing the first letter of the controller name.
Controller name should start with capital letters.
If lower case is used, Controller generator won't throw any error, but you will get not found(404) error in the browser.
this threw an error:
app\controllers\testController
this worked:
app\controllers\TestController
Its very Simple, change the namespace and please be careful while creating CRUD..
change namespace app\controllers; to namespace backend\controllers;
Good afternoon,
I don't know if what I want to do is possible, so here goes.
I have a module that extends Page_Controller, but I want certain functions to be accessible via the site root.
Eg: getMyDataObjectList();
Currently, they only work if I go through the normal MVC routing structure.
I've found that when I place the function 'getMyDataObjectList' within '/mysite/code/Page.php' it works.The problem is, I don't want to place the code in there. I want it bundled with my Custom Module, but to work the same as though it was in 'mysite/code/Page.php'
[Example Scenario]
site root: http://[somesite].com
By default, the 'Page.ss' template loads.
I would like the theme developer to be able to call my module functions (API) within any template/Layout page, and have the result returned from the site root
Currently, this only works if I move the "API" functions to '/mysite/code/Page.php'
If the code is in my module, then data is only returned when you go to:
http://[somesite].com/[module_controller]
Can this be achieved? If so, how?
Thanks for your assistance.
[Update - Code Solution]
///>MyExtension.php
class MyExtension extends Extension{
public function getMyDataObjectList(){
return 'object list goes here!';
}
}//class
///>[Module] => _config.php
Object::add_extension('Page_Controller', 'MyExtension');
And as always, I do a (/dev/build?flush=1) just in case.
Thanks to: 'simon_w'
Yes, this is relatively straightforward. Simply, create an Extension subclass with your methods in them and then add that to Page_Controller. An Extension subclass is almost exactly the same as a DataExtension, they're just for classes other than DataObjects.
I have followed this setup, but not work for me http://www.cniska.net/yii-bootstrap/setup.html, all CSS files do not give style to the page,
So searching I found this thread How to install bootstrap extension in yii using some tricks. But not work's too.
Now I have this error
'Property "CWebApplication.bootstrap" is not defined.'
Anyone can help or have any idea?
Thanks in advance and for my English.
Property "CWebApplication.bootstrap" is not defined.
The error means the system is trying to access Yii::app()->bootstrap, which could be a property on the application. Since bootstrap is a component it should be accessible, if the configuration is done properly.
This error is most likely because you forgot the following in the main config file:
'components'=>array(
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
),
// This should point to the location you placed the files in for example extensions/bootstrap/components/bootstrap.php
The class location above will only work if the alias is set properly before setting the configuration.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
Instead you could also change "bootstrap.components.Bootstrap" into "application.extensions.bootstrap.components.bootstrap".
I strongly advise you to use Yiistrap, it was made by the person who create yii boostrap and the person who created Yiibooster. Yiistrap has everything from both extensions and more new stuff. here is the page http://www.getyiistrap.com , also has a fully documented API which yii boostrap do not have and it will save a lot of google searches.