I would like to understand and build a SAAS with YII.
Now, I try to find as much information as I can before getting started.
But there’s still something I don’t get is how to store CODE content in the database.
We think about approaching the problem this way:
Controller
-Views: Template1 -> run code from DATABASE(TenantID)
-Views: Template2 -> run code from DATABASE(TenantID)
-Views: Template3 -> run code from DATABASE(TenantID)
After creating DB connection dynamically to the Tenant DB, we run the code from the DB to render the view template associated. Inside the template the code content will be pull out the DB and run.
Modules might be called as a service to run according to the tenant.
Now that being said, is this a good approach?
I mean to use the DB to push, pull, run code is this a good idea? or we can just use metadata to represent elements and then render them?
Can anyone point me to some algorithms, documentation, tutorials, examples of any kind about modern SAAS function I would really appreciate
There are a few posts about using Yii in a SaaS environment but they all focus on using a shared DB instead of individual DBs per client. Without knowing the scope / size of your project its hard to say but if you have the opportunity to go shared it greatly simplifies your environment.
That said,
Why are you storing code to eval in the database? Is this user-changeable view code? Have you questioned the assumption that you need to store code? If this is about storing user-generated content a good approach is to use BBcode / markup or a WYSIWYG editor and store both raw and html versions in your table. Use HtmlPurifier to remove any security threats.
That one DB per Tenant is easy to start but may cost more with time in contrast with one DB for everyone. I still don’t follow that logic, and find 1DB/1tenant common sense as for a managing stand point…But I begin to ask myself if monitoring hundreds of separate DB is really more practical.
"size of your project" we already design website for clients the traditional way but rewrite the code again and again event with help of reusable modules and extension make little to no sense to us. And updating new versions of our modules for all clients… is a nightmare -.-"
We want to be able to host hundreds of corporate sites with different services according to needs.
I’m still trying to understand what’s the best approach to use pre-made templates… but be able to customize the code WITHOUT touching other client template.
Dynamic code + LESS is the best idea I came up with… please share your ideas, experiences and documentation… I try put this thing together
CREATE TABLE foo_base (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
tenant VARCHAR(16),
foo VARCHAR(64),
bar VARCHAR(64)
);
CREATE VIEW foo AS
SELECT id, foo, bar
FROM foo_base
WHERE tenant = SUBSTRING_INDEX(USER(), '@', 1);
CREATE TRIGGER foo_base_tenant_trigger
BEFORE INSERT ON foo_base
FOR EACH ROW
SET new.tenant = SUBSTRING_INDEX(USER(), '@', 1);
i created model for the view foo, but cant create crud because that has no Pk. thats ok.
so i created model for foo_base and crud for the same. And when using the model Foo (not Foobase). its working perfectly according to DB user. its only fetching the current user’s value. but in Yii we are using lots of PK(primary key) based operations. like findByPk . so how i solve this?