Hot answers tagged

9

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 Craft CMS 3’s Debug Toolbar article


5

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 the following to your init() code: // In dev envs override user debug toolbar prefs based on devMode setting if (getenv('ENVIRONMENT') === 'dev' && ! ...


5

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 to your config/app.php: 'local' => [ 'bootstrap' => ['debug'], 'modules' => [ 'debug' => [ 'class' => 'yii\debug\...


4

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 haven't been able to find any documentation describing where/how to set this. From your Craft config/app.php file, you can use this to set the isWindows ...


4

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 {{ craft.app.request.getParam('foo') }} {# Should be the value of the input named 'foo' #}


3

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/


3

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->lastName = $lastName; $user->username = $userName; $user->email = $email; $user->password = $password; if ($user->validate(null, false)) { Craft::...


3

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 on an event in the Browser, but that at that time, there is no longer Twig, just HTML. So your solution will need to involve Javascript to change the HTML/DOM ...


3

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(); Assuming category is the name of your relational field, you can use that to pass the and condition (though with one element only it wouldn't be needed) then ...


2

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' => array('type' => AttributeType::Mixed, 'model' => 'Shipper_ShippingItemModel'); Regardless, you'll want to use BaseModel's setAttribute to do what you'...


2

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's Controller. Each step in the form can be another action on the controller. You can persist data between form steps by saving to Craft's HttpSessionService, ...


2

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 preview status (not even alpha release), but the next release will include updated Composer dependencies.


2

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 stack trace shown. You can see your 404 template by requesting it directly, e.g. http://mysite.dev/404 https://github.com/craftcms/cms/issues/1613#...


2

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: $craft->entries->saveEntry(); Along with your models, records, etc.


2

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 Enhancing a Craft CMS 3 Website with a Custom Module for details. You can also generate your module scaffolding via pluginfactory.io


2

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 mode (under the PHP tab of MAMP Pro). If that works, then try reverting to CGI mode. You may find it continues to work.


2

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 you're really using an alias that points to the yii\validators\NumberValidator class. See yii2/validators/Validator.php to see a list of default aliases created ...


2

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


2

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 extends TransformerAbstract { private $user; public function __construct($user) { $this->user = $user; } public function ...


2

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 of directly sorting speakers. Working code: {% for speakerKey in speakers|keys|sort %} {% set speaker = speakers[speakerKey] %} <li>{{ speaker....


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 an fix within 48 hours. Update to the latest version of Craft, this has already been fixed.


1

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 * If set to false, you are required to be logged in to execute any of the given controller's actions. * If set to true, anonymous access is allowed for all ...


1

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>/<controller>/<action> URLs), simply add this line of code at the top of the action's method: $this->requireCpRequest(); The non-CP action URLs will ...


1

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::EVENT_INIT, function(Event $e) { $e->sender->set('phpaccess',services\yourService::class); }); Access functions within this service in ...


1

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 work". I'd suggest going over to https://pluginfactory.io/ and select with Craft 3 plugin or module and tick the "Console Commands" checkbox to see a working ...


1

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 to move the bootstrapping part to the service init() method and save the database connection as a private instance variable in the service so everything in the ...


1

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 ()) Thus your code should look like: public function updateUserName($userId, $updateUser) { $update = craft()->db->createCommand()->update( '...


1

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 everyone with minor knowledge. Furthermore you are mixing Craft 2 with Craft 3. There is no userSession in Craft 3. I don't want to post a code snipped that would ...


1

I just had this issue and I found that I caused it by setting the defaultCookieDomain to something else, than where my Craft website was running. The effect was that the CSRF cookie was never sent to my server when logging in, so CSRF failed. Removing/updating the defaultCookieDomain setting from/in general.php file should fix the issue.


1

After discussions on Craft Slack and with Brandon on GitHub it was noticed that one component in Gulp had a path set to compile some files out into a /web directory, even after I'd changed my project to use the /public directory instead. So I think Craft was getting confused between /public and /web. This also lead to the /public directory having an out of ...


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