Unknown Class – yii\base\UnknownClassException Yii2 - model-view-controller

I am a beginner in Yii2.I am studying Yii2 from this Yii2 documentation link.When I run this file,its giving me the following error.
I have created a CountryController within C:\xampp\htdocs\yii\frontend\controllers\CountryController.php.
EDIT:
After modifying the namespace in controller,Now am getting issue in View.

The error message is basically saying that it cannot find your Controller. So what you need to do is ensure that your file is stored in the same place as your namespace implies. My suspicion is that they don't align. So...
You are using the namespace of app\controllers but you store your file in yii\frontend\controllers. I suspect yii\frontend\controllers does not correspond to app\controllers. I suspect, all you'll have to do is use the namespace frontend\controllers - but it depends on what aliases you are using.

Related

Laravel Override View::make namespace, cashier specific

How would I override the View::make('cashier::receipt'); view so that when that particular namespace is called like that, it checks my folder first and then defaults back to the vendor path.
View::addNamespace('cashier', [
'/path/to/my/views', // check first
'/path/to/original/views' // check second
]);
I believe that's how Laravel handles custom views for packages already. https://laravel.com/docs/5.2/packages#views - see Overriding Package Views here.
Laravel registers two locations to load views so they can be easily customised, the standard vendor path and something customisable.
Laravel will first check if a custom version of the view has been provided by you, for example in
resources/views/vendor/cashier.
Let me know if there was something more specific you were trying to achieve but I believe the info there will get you going.

Default blade directives in Laravel/Lumen

Where can I find the default blade directives folder?
I was looking for the #forelse to take as example, but I couldn't find it.
Does anyone know where they are defined in Lumen/Laravel?
note: I'm using Lumen framework, but I think it's quite similar to Laravel in this question, so I'm tagging both.
EDIT:
Due to the imprecision, I'll explain better my intention.
Basically, I'm creating a directive exactly the same as #forelse, but with 2 or 3 further information.
For that reason, I came to ask about the location since I haven't found by myself.
They're defined in the Illuminate\View\Compilers namespace in the BladeCompiler.
See Illuminate/View/Compilers/BladeCompiler.php
Specifically you'll need the compileForelse method if that's the one you want as an example.

Symfony translation inside validation won't work

If I try to use translations inside validation like described here
http://inchoo.net/tools-frameworks/symfony2-translating-validator-messages/
I get always
not.blank.username
as output on Error. It seems like symfony didn't find the message-translation. I placed all my translationfiles inside app/ressources/translations and they are named as
messages.de.yml
....
What am I doing wrong? Do I have to place the translationfiles insde each Bundle?
Kind regards
EDIT: Problem ist clear and fixed, but when I try to use "MinLength" I get an strange error:
Attempted to load class "MinLength" from namespace
"Symfony\Component\Validator\Constraints" in /var/www/symfony/webprojekt/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php line 64.
Do you need to "use" it from another namespace?
I already included
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\MinLength;
use Symfony\Component\Validator\Constraints\MaxLength;
AM I missing something?
To translate validation messages you need to create files with the following name structure inside translations folder:
validators.LANG.yml
Also, you can check in your config.yml, inside framework, if exists the translator:
framework:
translator: { fallback: %locale% }
This is required.
The accepted answer applies to using the magical default translation domain for the validator config. You can also override this in config/packages/validator.yaml
framework:
validation:
enable_annotations: true
translation_domain: 'validations'
Then in translations/ make a file validations.LANG.yaml, for example translations/validations.en.yaml. You don't need to do this but sometimes it's better to explicitly set these magical bit and know where they're coming from.

EnvDTE CodeClass.AddDelegate overload

I want to create 2 delegates with the same name but different parameters (overloaded delegate). When I try to add a delegate I get an error on the second try due to a delegate already existing. I tried to add it first with a temp name then add the parameters and then change the name so the signuature would be different but I still get an error stating that an item already exists with that name.
How can I add an overloaded delegate?
The capabilities of the code model to generate code are limited. You can try the to use EditPoint.Insert(...) to insert the code instead of using AddDelegate() method.

get magento module config data in Observer

I created a module with an observer for the sales module with event hook ‘sales_order_shipment_save_after’ ,
My module has the following files
Company/Modulename/etc/config.xml
Company/Modulename/etc/system.xml
Company/Modulename/Model/Observer.php
there are four fields in the modules admin configuration fields
I want to get those saved data in the Observer class.
using $this->getConfigData(’password’); gives a
Call to undefined method
error
Any suggestions?
Magento uses a static method on the global Mage application object to get configuration values
$config = Mage::getStoreConfig('section_name/group/field'); //value
$config = Mage::getStoreConfig('section_name/group'); //array
An amendment to Alan's completely correct answer.
Along with path as first parameter, getStoreConfig also accepts storeid as second parameter(optional).
Well, this is useful when you want to retrieve store-wise values.
Alan has mentioned this point in his own tutorial. I guess, he has not mentioned here just because OP has not mentioned this requirement in his question.
Please refer this
In a shipment module I can use $this->getConfigData for fields in system.xml, but in another kind of modules sometimes not, e.g. extends Mage_Core_Model_Abstract, than I must use getStoreConfig. So the answer is you don't have to use always getStoreConfig. But I don't know why ...
Answer: getConfigData is just defined in a shipment class and uses getStoreConfig too. A little confusing that some functions are extra defined and unneeded in fact ...

Resources