I have Yii2 application which uses the webvimark/user-management module to deal with Users. I've created additional model called UserProfile which adds some additional functionality and fields. For those interested, I followed this guide:
https://github.com/webvimark/user-management/wiki/Profile-and-custom-registration
I got pretty much everything working, having a custom registration form created to work with the new profile fields. The only problem that I have is how to replace the original form included in the module without modifying it. In here, webvimark suggests to use theming to do so:
https://github.com/webvimark/user-management/issues/10
How do I theme just that one file containing the form though? I wouldn't want to change the rest and all the examples of theming I can find overwrite a whole directory. Any suggestions?
After a lot of head banging it turns out that the answer is quite simple. You do have to use theming for the whole directory as there is apparently no other option. However, I found this little article, which says that once you use theming and your controller tries to load a view then it will be first searched under the new theming directory that you created BUT if it's not found there, you go back to the original directory.
In other words, you overwrite the whole directory but if you provide only one view in the new one, the rest will stay the same, which is quite beautiful.
I'm posting the code that I wrote down in my web config file just in case someone struggles with paths:
'components' => [
'view' => [
'theme' => [
'pathMap' => [
'#app/vendor/webvimark/module-user-management/views/auth' => '#app/views/user-profile'
],
],
],
],
Related
By default Yii2 generates file web/index.php with defined('YII_DEBUG') or define('YII_DEBUG', true); line. It's entry point of any page on site. And this the first line of a code. So checking for defined YII_DEBUG seems meaningless. I suppose this constant can be defined in something else place. But can't find where to do it.
In my personal case I have a local version of site and want to enable this constand for debugging purposes but don't want to change web/index.php. This file is under VCS (git) and I don't want to accidentally enabled debug in production.
StackOverflow has allready similar question. But it targeted on other sense and didn't give answer on my question. So I just created a new question.
Even if the index.php is default entry point for Yii app, you can still create your own entry point, include the index.php in it and set web server to use that file instead of index.php.
For example you can create custom-entry.php like this:
<?php
define('YII_DEBUG', false);
// do something ...
require index.php;
Or you can define YII_DEBUG in some script that is run at start of each request by auto_prepend_file directive.
But those are not exactly best options how to deal with your case.
In your case I would suggest to simply set your versioning system to ignore local changes of index.php file. For example if you are using GIT you can use skip-worktree flag to do that. I don't know CVS much so I'm not sure how exactly it is done with that.
Yii does it like that
defined('YII_DEBUG') or define('YII_DEBUG', true);
which means that if it's not defined already - define it.
This is a proper place to define it. The above statement is just in case somehow you got this already defined by any mean which Yii will honor.
So I'm currently working myself through the following introduction about extension developement for TYPO3:
https://docs.typo3.org/m/typo3/book-extbasefluid/9.5/en-us/4-FirstExtension/4-make-products-persistent.html
There it says
TYPO3 is able to group all records of an extension in the new record wizard. To define the name of this group, create a language file in the directory EXT:store_inventory/Resources/Private/Language/ and add the key extension.title.
What do I therefore have to name the language file (you might also want to check the link) for it to work and what exactly is meant by "add the key extension.title"?
Filenames of language files are created with several patterns
typo3conf/ext/extkey/Resources/Private/Language/locallang_db.xlf
Is used in Backend i.e. for displaying the name of the tables, names of fields in the backend edit form, plugins etc. Naming convention here is rather strict. i.e.:
<trans-unit id="tx_extkey_domain_model_yourmodel.name">
<source>Name</source>
</trans-unit>
can be used in the TCA of your model like:
'name' => [
'exclude' => true,
'label' => 'LLL:EXT:extkey/Resources/Private/Language/locallang_db.xlf:tx_extkey_domain_model_yourmodel.name',
'config' => [...],
],
typo3conf/ext/extkey/Resources/Private/Language/locallang.xlf
Is used in FrontEnd, so for an instance
<trans-unit id="my_list_header">
<source>This is list of my elephants</source>
</trans-unit>
can be accessed within your Fluid template like
<h1><f:translate key="my_list_header"/></h1>
Note: as you can see naming convention for id/key, in this case, is more flexible, then in case of *_db.xlf files.
typo3conf/ext/extkey/Resources/Private/Language/locallang_csh_tx_extkey_domain_model_yourmodel.xlf
Is for adding CSH - Content Sensitive Help
<trans-unit id="name.description">
<source>That's just the record's name Sherlock!</source>
</trans-unit>
In Backend looks like:
You can also add [fieldname].details node to XLIFF file and then it will allow displaying more detailed help for the field in the popup window.
<trans-unit id="name.details" xml:space="preserve">
<source>Sherlock Holmes (/ˈʃɜːrlɒk ˈhoʊmz/ or /-ˈhoʊlmz/) is a fictional private detective created by British author Sir Arthur Conan Doyle.</source>
</trans-unit>
TIP
Although learning of creating TYPO3 extensions from the scratch is quite romantic I'd suggest starting from installing extension_builder extension and creating own extension's skeleton within minutes or even seconds. It will create most of the required elements, like SQL insertion, language files, TCA and TypoScript configuration files and many more, so you can investigate it against tutorial easier.
About the key
I may be wrong, just don't remember now, probably extention.title was some approach in a pre-Extbase way, years ago. Nowadays I didn't meet it in any extension which works with ver 9.x or 10.x. It's obviously missing part in documentation you mentioned in yor question and it should be rather fixed there, to be more detailed.
I would have thought that your file should be extention.title
The CakePHP docs on using the FormHelper suggest I should be able to create new templates for its output once, and use this throughout my project.
As described it requires modifying the loading of the FormHelper, from this:
$this->loadHelper('Form');
to this:
$this->loadHelper('Form', [
'templates' => 'app_form',
]);
where app_form refers to a file in the config directory. However, I haven't had to actually load the FormHelper at all, it's magically available already, and if I try to do the above I get an error to the effect the helper has already been loaded:
The "Form" alias has already been loaded with the following config: array (...
Don't know if the docs are out of sync with the current version of CakePHP, but I can't see how to use this functionality - anyone know?
I am building a product that is based on the Yii2 advanced template.
As part of this product and its future deployments, I am trying to automatically create the tables related to Authorization in a regular Yii2 migration.
E.g, when the end user installs the product and runs the regular Yii migration commands he should have a fully functional user management AND authorization active.
For authorization to work, the Yii2 RBAC documentation page states that 4 tables are needed (auth_*). The documentation states that they are created by running the following migration:
yii migrate --migrationPath=#yii/rbac/migrations
I'd like to offset this extra hassle from the end user by running this specific migration code for him inside a regular migration that will be stored in common/migrations.
Any easy solution for this?
I have created a migrate.sh file where I put my migration commands that I need to run. This allows me to migrate from multiple places in the same time. It is quite simple, take a look here: https://github.com/Mihai-P/yii2-app-advanced/blob/master/migrate.sh
Instead of running ./yii migrate/up i just run sh migrate.sh that will update everything from any place.
The actual point of this is: you do not have to stick to exactly what Yii gave you. That is just a template for you to build on. Fork it, modify it, make it your own.
Try to add in console/config/main.php:
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => [
'#console/migrations',
'#yii/rbac/migrations',
]
]
],
Another approach (not using *.sh file) is to copy the rbac_init migration to your migrations folder:
cp vendor/yiisoft/yii2/rbac/migrations/m???????_rbac_init.php console/migrations/
Now, when you run php yii migrate it will be included the rbac_init migration.
I know this is pretty old question, but here is easy solution, create migration file and have this code in that file
<?php
require(Yii::getAlias('#yii/rbac/migrations/m140506_102106_rbac_init.php'));
/**
* Class m220225_133725_init_rbac
*/
class m220225_133725_init_rbac extends m140506_102106_rbac_init
{
}
I have been reviewing documentation in the cookbook to generate custom HTML in baked views and I'm having difficulty in getting my custom code to run during the bake process.
I followed the instructions as stated which are:
Modify default HTML produced by “baked” templates¶
If you wish to modify the default HTML output produced by the “bake” command, follow these simple steps as outline at http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html
For baking custom views
Go into: lib/Cake/Console/Templates/default/views
Notice the 4 files there
Copy them to your: app/Console/Templates/[themename]/views
Make changes to the HTML output to control the way “bake” builds your views
The [themename] path segment should be the name of the bake theme that you are creating. Bake theme names need to be unique, so don’t use ‘default’.
For my "theme" I chose the name dalma and placed my modified versions of the view generation code in
app/Console/Templates/dalma/views/
and then rebaked a specific table and none of my changes appeared.
I had assumed that I would be prompted for a theme when I ran the bake from the CLI which was not the case.
I then found instructions which talk about assigning a theme in the AppController which I did and this did not help.
Next I found another article http://www.dereuromark.de/2010/06/22/cake-bake-custom-templates/ that talked about placing the custom code in the app/vendors/shells/dalma/ directory and this did not work
I would appreciate any assistance.
You have to have a layout specified in your appController that matches the folder name in Console/Templates
appController.php
public function beforeFilter(){
$this->layout = 'bootstrap';
}
Console/Templates/bootstrap has my bake template.
With this setup the bake console prompts me for a template choice. (there may be other ways to specify this)
Here is my custom bake template which should help. (this is a forked work and not all my original code)
https://github.com/arco000/BootstrapCake