Posts

Showing posts from September, 2022

How Do You Work With Diverse Layouts in Your Application Using Yii2?

Image
  In this article, we’ll show you how to create various layouts for action views in your app. We assume, for example, that our application’s pages will employ three alternative layouts: A one-column layout has only the main content area; a two-column layout has a left sidebar displaying portlets and the main content area; and a three-column layout has a left sidebar displaying portlets, the main content area, and a right sidebar displaying some context information. Creating Layouts The 960 Grid System is used to simplify the CSS design. Because all three layouts have the same header and footer sections, we start with the primary layout, which will be the parent of the three. All of these layout files are kept in the protected/views/layouts folder. Making Use of Layouts The layout of a page (produced by calling [CController::render]) is primarily governed by two properties: [CWebApplication::layout] and [CController::layout], as we know. The former specifies the global layout for all pa

How Does One Manage Insights on Yii2 Websites?

Image
  Work on the main thread should be kept to a minimum Consider shortening the time it takes to parse, compile, and execute JS. You might find that sending smaller JS payloads helps. JavaScript that isn't in use should be reduced To reduce the number of bytes spent by network activity, reduce unneeded JavaScript and defer loading scripts until they are required. CSS that isn't in use should be reduced Reduce the number of bytes spent by network activity by removing unneeded rules from stylesheets and deferring CSS that isn’t used for above-the-fold content. Ensure that text is visible while the web font is loading Use the font-display CSS property to ensure that text is visible to users while web fonts are loading. Third-party code should be minimized Third-party code can have a big impact on load times. Limit the number of duplicate third-party providers and load third-party code after your page has finished loading in its entirety. With an efficient caching policy, serve stati

What is an Event in Yii2?

Image
  Because PHP doesn’t contain actual events like JavaScript, event programming isn’t always familiar territory for PHP developers. The only true event in PHP is handling a PHP script’s request (through a direct link or a form submission). The PHP code in that script is performed as a result of that event occurring. In JavaScript, on the other hand, you may have your code watch for and respond to a variety of events (such as a form’s submission, the movement of the cursor, and so on) as long as the browser window is open. Yii adds additional event capability to PHP-based Web sites thanks to the component class.   In any language, event handling begins with the declaration “when this event occurs with this thing, call this function.” You can construct your events in Yii, but models have their own set of predefined events to keep an eye on before a model is stored, after a model is saved before a model is verified, and so on (the available events will depend upon the model type). Yes, eac

What is Active Record in Yii2?

Image
  Active Record is database access and manipulation tool that uses an object-oriented interface. An Active Record class is linked to a database table, an Active Record instance is linked to a table row, and an attribute of an Active Record instance is linked to the value of a specific column in that row. To access and alter the data stored in database tables, you would access Active Record properties and invoke Active Record methods instead of writing raw SQL commands. What is Yii2's character? The Yii base Behavior class is used to create behaviours. A behaviour attaches itself to a component and injects its methods and properties into it. Behaviour patterns can also react to the events that the component has caused. What should you do if a Yii DB exception is thrown? Sets a callable (e.g., an anonymous function) that is called when the yii\\db\\Exception is thrown during the command execution. The callable’s signature should be: The default fetch mode for this command is the DB c