Hi All -
I stumbled upon this article, written by qiang in the Wiki.
Now that I have seen this, everything about Yii and how to actually make a real world project happen — is starting to make sense.
I really like this structure and now I need to figure out how to implement it! As it is right now, I run ‘yiic webapp /path’ and it makes a project show up. How do I implement this new project structure?
Is there a command? (doubt it, but had to ask…)
If I take the generic "webapp" that yiic produces and just move the folders around, will that be sufficient or would I just need to perhaps update the path locations in a config file somewhere?
Ideally, if I could translate the project structure into:
I guess I’m struggling on where to get started with this…am I on the right track?
You could play around with the WebAppCommand but I wouldn’t suggest that. Much quicker just to move the folders around manually. The only file I needed to change was index.php - to point to the new framework folder and protected/config/main.php locations.
Ok, I’ll start there. The wiki page had a few nice commands to get the file structure setup, then I could just drop my files into the right places…or modify the pre-generated version.
How would application access work? In my post I noted a few links, so if I had /backend/ as a Yii application folder, it would be like a subdirectory in the actual website (for example)?
I’ll struggle with it tomorrow morning, but I’m wondering if it is all THAT straight-forward. My spider sense is telling me “no”.
So you backend will contain the contents of protected? If so, all you need to change is the index.php file.
$dirMainPath = dirname(__FILE__);
$config = require($dirMainPath . '/backend/config/main.php');
If you check on the original project layout, you will see that backend, frontend, common all contain components of the protected folder. That’s so backend and frontend can both reference shared models, etc… from common.
At least that’s how I understood it. So there really isn’t a protected folder, its all outside the “www” folders, which are now nested inside each “application”.
Does that make sense? Aside from your ideas, I’m not sure how to get this implemented. I’ll start playing with it now and see what happens.
I was able to get this structure working properly, and I really like the separation of common application components. It’s really quite simple actually, 2 things need to be done to make the applications talk to each other.
- Edit you config/main.php in backend and frontend to have the "site" level path alias included:
- Import the shared models, using the config/main.php in backend and frontend like this:
// autoloading model and component classes
Done…pretty cool if you ask me. Now I can build models for data tables that get accessed from both the backend and frontend of my application. In the future, I’ll add an API application to the mix and it will be a snap!
More people should use this structure, it’s really the piece I was missing from the initial yiic generated code! If the yiic sample stuff leaves you scratching your head and wanting more, then this will surely satisfy the itch!