Hot answers tagged

9 votes
Accepted

Craft 3: how to show the Yii Debug Toolbar?

There are two checkboxes in your user settings, go to your admin account -> preferences index.php?p=admin/myaccount and check the boxes This is covered in detail in the Profiling your Website with ...
user avatar
5 votes

Craft 3: how to show the Yii Debug Toolbar?

For anyone finding it annoying having to be authenticated to enable the debug bar, particularly when testing in multiple browsers, it’s easy to override this behaviour with a custom module. Just add ...
user avatar
5 votes

Craft 3: how to show the Yii Debug Toolbar?

Craft 3 If you enabled the debug toolbar in the user profile, but it still does not show on the frontend, AND you are running Craft not locally but on a different host (different IP), try adding this ...
user avatar
  • 608
5 votes
Accepted

How to access HTML input values from Twig and vice versa

You can do it without JavaScript (if you don't mind the page refreshing) by accessing the request variable: https://docs.craftcms.com/api/v3/craft-web-twig-variables-request.html#public-methods {{ ...
user avatar
4 votes

Craft CMS V3 Create New User

Take a look at Craft's own UsersController->actionSaveUser(). You're probably looking for something closer to this: $user = new craft\elements\User(); $user->firstName = $firstName; $user->...
user avatar
  • 66.3k
4 votes
Accepted

PHP Fatal error during installation

See this issue: https://github.com/craftcms/cms/issues/4355#issuecomment-498829513 reproduced here for completeness: A yii variable 'isWindows' is apparently the way to correct this issue, but I ...
user avatar
3 votes
Accepted

Joining two plugin tables by reference Id causes duplicates

You're probably looking for an inner join (which Yii just calls a join)instead of a leftJoin: https://blog.codinghorror.com/a-visual-explanation-of-sql-joins/
user avatar
  • 66.3k
3 votes

Craft 3 404 and 503 pages in devMode

Just posting this here since I saw an official answer in Github: This changed in Beta 7: UserException reports are now styled like other exceptions when Dev Mode is enabled, with the full ...
user avatar
3 votes

How to access HTML input values from Twig and vice versa

Twig (at least within the context of Craft) doesn't work this way I'm afraid. The Twig template is processed on the server and HTML is returned to the browser. You're trying to change the Twig based ...
user avatar
  • 1,969
3 votes
Accepted

Combine AND and OR in a ElementQuery

If I understand properly, you should be able to do this: $entries = \craft\elements\Entry::find() ->section('yourSection') ->category(['and', 695]) ->relatedTo([698,698])->all()...
user avatar
  • 7,085
3 votes
Accepted

Debugging with dump()/dd() within Twig templates

This bothered me too until I switched to PHPStorm and started using this: https://github.com/nystudio107/craft-autocomplete. If that's not an option and you fancy extending Twig, you can use php's ...
user avatar
  • 3,794
2 votes
Accepted

How to add to arrays in models?

I'm pretty sure 'default'=>[] isn't doing anything so it's probably not necessary. If you wanted to force a single attribute to be of a specific model, you could use: 'courierShippingItems' =>...
user avatar
  • 66.3k
2 votes

Multi-page form with Yii in a Craft site?

I wouldn't worry going so far outside of Craft and using Yii's forms. Sounds like all you need is a Craft plugin. Use normal HTML <form>s from your template and have them post to your plugin'...
user avatar
  • 66.3k
2 votes

CraftCMS 3 - Composer Update

You can't. The composer.json file (and the composer.lock file so you can't even reverse engineer composer.json) isn't shipped with the official release on purpose. Craft 3 is still in development ...
user avatar
  • 66.3k
2 votes
Accepted

Craft equivalent to Rails runner

Maybe you're just looking for a bootstrapped Craft instance? Something like: $craft = require '/path/to/craft/app/bootstrap.php'; From there you'll have access to the Craft instance as usual: $...
user avatar
  • 66.3k
2 votes

Craft Rules and Validation

I just figured out the answer so I'm going to post it if anyone else is asking this question. Yii accepts aliases as well as function/class names when evaluating the rules function. When using number ...
user avatar
2 votes

400 error logging into local Craft 3 project

I haven't seen this particular issue but generally I've found that from time to time MAMP doesn't like running Craft in CGI mode, i.e. with different PHP versions per host. Try switching it to module ...
user avatar
  • 1,969
2 votes
Accepted

Yii Modules in Craft, samples?

In the context of Craft CMS, Modules typically would be used for adding functionality to the website itself. As such, you'd use it for things that are specific to that project. Check out the article ...
user avatar
  • 10.9k
2 votes
Accepted

Custom module controller getView()->renderTemplate() path not working

The correct path would be return Craft::$app->getView()->renderTemplate('subscribing-module/templates/default',['mypost' => $request]); And the file lives in modules/subscribingmodule/src/...
user avatar
2 votes

Pass params to transform function of Transformer class in split Transformer class

Here's how you would do that... Pass your parameter to the class: 'transformer' => new MyTransformerClassName($user), Use a constructor to save it as a property: class MyTransformerClassName ...
user avatar
2 votes

Nesting level too deep - recursive dependency?

I figured this out, with help from a GitHub thread or too. It appeared that using the sort filter on an array of objects was problematic. I was able to fix this by sorting the keys in speakers instead ...
user avatar
  • 736
1 vote

Craft 3 icons not found in craftcms/cms/src/icons

Gitignore had a line for Icon? which was causing the icon folder to not show up in git commit.
user avatar
  • 293
1 vote
Accepted

upgrade issue Yii Framework from version 2.0.15.1 to 2.0.16.1

Not sure about the Yii message, though it may be irrelevant. The Twig message refers to an issue where Twig itself was upgraded (to 2.7.2) which broke Craft. The makers of Craft were able to publish ...
user avatar
  • 23.6k
1 vote

How do I prevent a controller from creating unwanted routes?

I think you're "fighting the system" for no great gain, but anyway I think this is what you want: /** * @var bool|string[] Whether this controller’s actions can be accessed anonymously *...
user avatar
  • 10.9k
1 vote
Accepted

How do I prevent a controller from creating unwanted routes?

After too much time spent on this, I think I found a solution to both issues. 1) To prevent controller actions meant for the CP from being accessible on the front-end (via actions/<module>/<...
user avatar
  • 226
1 vote
Accepted

Integrating Yii 2 modules and frontend widgets with Craft CMS 3

If you go down the route of creating your own modules for craft/yii2: You can register access from twig to PHP services in your modules init() function Event::on(CraftVariable::class, CraftVariable::...
user avatar
  • 188
1 vote
Accepted

How do I create console commands for my module or plugin?

What's the equivalent for registering console commands? You don't need to listen to an event to create a console command. Assuming your namespacing and autoloading is set up correctly, they'll "just ...
user avatar
  • 66.3k
1 vote
Accepted

Connect to an external database from a Craft 2.x plugin

If only the service will be connecting to it and only one method, then your example works fine. If only the service will be connecting to, but you use it across multiple methods, then you might want ...
user avatar
  • 66.3k
1 vote
Accepted

where command sql query not working

When you take a look at the documentation the interface for the update function is the following. public integer update(string $table, array $columns, mixed $conditions='', array $params=array ()) ...
user avatar
1 vote
Accepted

Craft 3 Element API Authentication/Login

First of all passing the password and username as query strings is one of the most insecure things you can do. It would highly suggest you to not do that unless you want to expose your accounts to ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible