<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Antonio</title>
    <description>The latest articles on DEV Community by Antonio (@amaristany).</description>
    <link>https://dev.to/amaristany</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1218631%2F6160e622-c203-474a-aa51-1be6010d1085.png</url>
      <title>DEV Community: Antonio</title>
      <link>https://dev.to/amaristany</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amaristany"/>
    <language>en</language>
    <item>
      <title>Multitenancy in Yii2: Practical Guide and Code Examples</title>
      <dc:creator>Antonio</dc:creator>
      <pubDate>Wed, 26 Nov 2025 12:27:47 +0000</pubDate>
      <link>https://dev.to/amaristany/multitenancy-in-yii2-practical-guide-and-code-examples-4b5l</link>
      <guid>https://dev.to/amaristany/multitenancy-in-yii2-practical-guide-and-code-examples-4b5l</guid>
      <description>&lt;h2&gt;
  
  
  Multitenancy in Yii2: Practical Guide and Code Examples
&lt;/h2&gt;

&lt;p&gt;Multitenancy is a powerful architectural pattern that allows a single application instance to serve multiple tenants (clients or organizations), keeping their data isolated. Yii2, being a flexible PHP framework, can be adapted for multitenant applications in several ways.&lt;/p&gt;

&lt;p&gt;In this article, I'll show you how to implement a basic multitenant setup in Yii2, including code snippets and best practices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approaches to Multitenancy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single Database, Shared Schema:&lt;/strong&gt; All tenants share the same tables, with a &lt;code&gt;tenant_id&lt;/code&gt; column to separate data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single Database, Separate Schemas:&lt;/strong&gt; Each tenant has its own set of tables (schema).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple Databases:&lt;/strong&gt; Each tenant has a dedicated database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this example, we'll use the &lt;strong&gt;Single Database, Shared Schema&lt;/strong&gt; approach, which is common and easy to maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Add a &lt;code&gt;tenant_id&lt;/code&gt; Column
&lt;/h2&gt;

&lt;p&gt;Add a &lt;code&gt;tenant_id&lt;/code&gt; column to your tables. For example, in a &lt;code&gt;posts&lt;/code&gt; table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;tenant_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Identify Tenant on Each Request
&lt;/h2&gt;

&lt;p&gt;You can identify the tenant by subdomain, domain, or request header. Here’s an example using subdomains.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Tenant Component
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// components/TenantComponent.php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;app\components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yii&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;yii\base\Component&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TenantComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$tenantId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Yii&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$app&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;hostName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$subdomain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;explode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="c1"&gt;// Example: map subdomain to tenant_id&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tenantId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getTenantIdBySubdomain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$subdomain&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getTenantIdBySubdomain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$subdomain&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Replace with your logic, e.g., query DB&lt;/span&gt;
        &lt;span class="nv"&gt;$map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'tenant1'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'tenant2'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$subdomain&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Register the component in your config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// config/web.php&lt;/span&gt;
&lt;span class="s1"&gt;'components'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// ...existing code...&lt;/span&gt;
    &lt;span class="s1"&gt;'tenant'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'app\components\TenantComponent'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="c1"&gt;// ...existing code...&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Automatically Filter Queries by Tenant
&lt;/h2&gt;

&lt;p&gt;Override &lt;code&gt;ActiveRecord::find()&lt;/code&gt; to always filter by &lt;code&gt;tenant_id&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// models/ActiveRecord.php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;app\models&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yii&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;yii\db\ActiveRecord&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;YiiActiveRecord&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ActiveRecord&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;YiiActiveRecord&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$tenantId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Yii&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$app&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tenant&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$tenantId&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;andWhere&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'tenant_id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$tenantId&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, make your models extend this base class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// models/Post.php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;app\models&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;ActiveRecord&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...existing code...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Set &lt;code&gt;tenant_id&lt;/code&gt; on Save
&lt;/h2&gt;

&lt;p&gt;Override &lt;code&gt;beforeSave&lt;/code&gt; in your base model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;beforeSave&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$insert&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;beforeSave&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$insert&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;isNewRecord&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Yii&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$app&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tenant&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Security Considerations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Always validate that users can only access their own tenant's data.&lt;/li&gt;
&lt;li&gt;Never trust client input for &lt;code&gt;tenant_id&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With these steps, you can implement basic multitenancy in Yii2. For more advanced scenarios, consider using separate databases or schemas per tenant.&lt;/p&gt;

&lt;p&gt;Feel free to ask questions or share your own approaches in the comments!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>php</category>
      <category>architecture</category>
      <category>database</category>
    </item>
    <item>
      <title>PHP and Angular: Direct File Upload to S3</title>
      <dc:creator>Antonio</dc:creator>
      <pubDate>Tue, 19 Mar 2024 17:50:37 +0000</pubDate>
      <link>https://dev.to/amaristany/php-and-angular-direct-file-upload-to-s3-2ohc</link>
      <guid>https://dev.to/amaristany/php-and-angular-direct-file-upload-to-s3-2ohc</guid>
      <description>&lt;p&gt;In this post, we will demonstrate how to allows users to upload files directly to Amazon S3 using PHP as a backend.&lt;/p&gt;

&lt;p&gt;By directly uploading these files to Amazon S3, you can avoid proxying these requests through your application server. This can significantly reduce network traffic and server CPU usage, and enable your application server to handle other requests during busy periods. S3 also is highly available and durable, making it an ideal persistent store for user uploads.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxj6o1nfad3hmohki2jn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxj6o1nfad3hmohki2jn.png" alt="Image description" width="800" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github Repo: &lt;br&gt;
&lt;a href="https://github.com/tonitomystery/upload-direct-s3-php"&gt;https://github.com/tonitomystery/upload-direct-s3-php&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>aws</category>
      <category>s3</category>
      <category>angular</category>
    </item>
    <item>
      <title>Why Yii2 is my choice for building REST APIs with PHP</title>
      <dc:creator>Antonio</dc:creator>
      <pubDate>Sat, 25 Nov 2023 16:17:14 +0000</pubDate>
      <link>https://dev.to/amaristany/why-yii2-is-my-choice-for-building-rest-apis-with-php-2adc</link>
      <guid>https://dev.to/amaristany/why-yii2-is-my-choice-for-building-rest-apis-with-php-2adc</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the world of web development, choosing the right framework for building REST APIs is crucial. After exploring several options, I have found Yii2 a powerful and efficient tool to accomplish this task. In this post, I will share the reasons behind my choice and why Yii2 excels in REST API development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Quick Implementation with Gii&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yii2 offers Gii, a powerful code generation tool that greatly simplifies the process of creating controllers, models, and views. This speeds up development time by automatically generating the code base needed for a functional REST API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Modular Structure and MVC&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Yii2 architecture, based on the Model-View-Controller (MVC) pattern, provides a modular and organized structure for API development. This facilitates the management and maintenance of the code, allowing a clear separation of responsibilities between components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. ActiveRecord and Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using ActiveRecord in Yii2 simplifies database operations and eliminates the need to write SQL queries manually. In addition, integration with various databases makes it easier to choose the storage technology that best suits the project requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Optimized Performance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yii2 has been designed with performance in mind. From the beginning, the structure of the framework is optimized to minimize loading time and improve application execution speed, which is essential in the development of efficient REST APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Extensibility and Customization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yii2's architecture allows easy extension of functionality through widgets, modules and components. This provides flexibility to adapt the API based on the specific needs of the project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Integrated Security&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yii2 includes built-in security features such as token management for authentication, protection against CSRF attacks, and other security measures that are essential when developing public or private REST APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Clear and Abundant Documentation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yii2's extensive and clear documentation is a significant advantage. The active community provides tutorials, guides, and examples that make it easy to learn and implement new features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Speed&lt;/strong&gt;, a key factor for any system or application, becomes one of the most prominent attributes of Yii2. Yii2's exceptional execution efficiency and responsiveness ensure that your REST APIs are not only powerful and versatile, but also extremely fast, providing an optimal experience for both developers and end users.&lt;/p&gt;

&lt;p&gt;Ultimately, the decision to leverage Yii2 for your next PHP-based REST API project goes beyond personal preference; it signifies a strategic move backed by a solid technical foundation and a committed community, providing the necessary tools to elevate your development to new levels of excellence, where speed becomes a pivotal component for the triumph of any system or application.&lt;/p&gt;

&lt;p&gt;I appreciate your attention and I hope this information has been useful.&lt;/p&gt;

</description>
      <category>yii2</category>
      <category>backend</category>
    </item>
    <item>
      <title>How to create an Angular application with Cornerstone to open a DICOM</title>
      <dc:creator>Antonio</dc:creator>
      <pubDate>Sat, 25 Nov 2023 14:35:43 +0000</pubDate>
      <link>https://dev.to/amaristany/how-to-create-an-angular-application-with-cornerstone-to-open-a-dicom-54al</link>
      <guid>https://dev.to/amaristany/how-to-create-an-angular-application-with-cornerstone-to-open-a-dicom-54al</guid>
      <description>&lt;p&gt;In this tutorial, you will learn how to create an Angular application with Cornerstone to open a DICOM file. Cornerstone is an open source library that provides an API for reading and writing DICOM files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Cornerstone?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cornerstone is a JavaScript library that facilitates the development of applications for working with medical images in the DICOM format. It provides a set of tools and utilities to handle image loading, manipulation, and rendering, making it easier for developers to build robust and feature-rich medical imaging applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use Cornerstone with Angular?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Integrating Cornerstone with Angular allows developers to harness the power of Angular's component-based architecture while leveraging Cornerstone's capabilities for working with DICOM files. This combination provides a solid foundation for creating modern and interactive medical imaging applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To complete this tutorial, you will need the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A code editor, such as Visual Studio Code or Atom&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Angular CLI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cornerstone&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Set up
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Generate the app
&lt;/h2&gt;

&lt;p&gt;Generate a new Angular app and add Cornerstone.js&lt;/p&gt;

&lt;p&gt;Use Angular CLI to generate a new Angular App.&lt;/p&gt;

&lt;p&gt;Run &lt;strong&gt;ng new cornerstone-app&lt;/strong&gt; in the command line, replacing cornerstone-app with the name of the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Cornerstone.js
&lt;/h2&gt;

&lt;p&gt;To integrate Cornerstone into your Angular application, follow these steps to include the necessary scripts in the &lt;strong&gt;index.html&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://unpkg.com/cornerstone-core@2.6.1/dist/cornerstone.js"&amp;gt;&amp;lt;/script&amp;gt;   

&amp;lt;script src="https://unpkg.com/dicom-parser@1.8.21/dist/dicomParser.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script src="https://unpkg.com/cornerstone-math@0.1.10/dist/cornerstoneMath.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script src="https://unpkg.com/cornerstone-wado-image-loader@4.13.2/dist/cornerstoneWADOImageLoader.bundle.min.js"&amp;gt;&amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Understanding the Added Scripts
&lt;/h2&gt;

&lt;p&gt;In the previous section, we added several scripts to our Angular application to incorporate the Cornerstone library. Let's take a moment to understand the purpose of each added script:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;cornerstone.js&lt;/strong&gt;&lt;br&gt;
This script is the core of the Cornerstone library. It provides the fundamental functionality for working with medical images in the DICOM format. It includes tools for image loading, rendering, and manipulation. Make sure to use the latest version available for optimal features and bug fixes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;dicomParser.js&lt;/strong&gt;&lt;br&gt;
The dicomParser library is responsible for parsing DICOM files. It provides methods to extract information from DICOM data, enabling Cornerstone to interpret and display medical images correctly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;cornerstoneMath.js&lt;/strong&gt;&lt;br&gt;
This script includes mathematical utilities required for image manipulation and processing within the Cornerstone library. It ensures accurate rendering and transformations of medical images.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;cornerstoneWADOImageLoader.js&lt;/strong&gt;&lt;br&gt;
The cornerstoneWADOImageLoader is an extension to Cornerstone that allows loading medical images using the WADO (Web Access to DICOM Objects) protocol. This script enhances Cornerstone's capabilities to retrieve and display DICOM images from a server.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The complete code for this tutorial can be found in the following GitHub repository:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/tonitomystery/cornerstone-angular"&gt;https://github.com/tonitomystery/cornerstone-angular&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to explore additional features offered by Cornerstone and customize your DICOM viewer further. If you encountered any issues or have questions, don't hesitate to refer to the provided GitHub repository or seek assistance in the developer community.&lt;/p&gt;

&lt;p&gt;Thank you for following this tutorial! Happy coding!&lt;/p&gt;

</description>
      <category>dicom</category>
      <category>angular</category>
      <category>cornerstonejs</category>
    </item>
  </channel>
</rss>
