Yii Framework Forum: Yii Project Planning & File System Layout - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Project Planning & File System Layout Rate Topic: -----

#1 User is offline   mbabineau 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-June 11
  • Location:San Diego, CA

Posted 25 October 2011 - 08:30 PM

Hi All -

I stumbled upon this article, written by qiang in the Wiki.

http://www.yiiframew...i-project-site/

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:

http://www.testyiisite.com/backend/
http://www.testyiisite.com/ (frontend)
http://www.testyiisite.com/api

I guess I'm struggling on where to get started with this....am I on the right track?

Thanks,
Matt
0

#2 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 545
  • Joined: 09-April 10

Posted 25 October 2011 - 09:12 PM

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.
0

#3 User is offline   mbabineau 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-June 11
  • Location:San Diego, CA

Posted 25 October 2011 - 10:23 PM

View Postwaterloomatt, on 25 October 2011 - 09:12 PM, said:

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". Posted Image
0

#4 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 545
  • Joined: 09-April 10

Posted 25 October 2011 - 10:45 PM

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');


0

#5 User is offline   mbabineau 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-June 11
  • Location:San Diego, CA

Posted 26 October 2011 - 10:46 AM

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.

Cheers,
Matt
0

#6 User is offline   mbabineau 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-June 11
  • Location:San Diego, CA

Posted 26 October 2011 - 01:25 PM

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.

1. Edit you config/main.php in backend and frontend to have the "site" level path alias included:

Yii::setPathOfAlias('site','/path/to/folder/that/contains/backend,frontend,common,console');



2. Import the shared models, using the config/main.php in backend and frontend like this:


	// autoloading model and component classes
	'import'=>array(
		'application.models.*',
		'application.components.*',
		'site.common.models.*',
	)



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!

-Matt
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users