Where to put What?

I am trying to figure out Yii/MVC stuff. I have some code/functions that I would like to use by including into a Yii WebApp.

Within the framework design, where would one put user defined include files so that someone who comes into maintain my code go to look for them. I understand I could put them anywhere, but in the directory structure of the framework, what makes sense?


Could you define what you mean by “user defined include files” please? :)

Are you talking about modules perhaps or external libraries?

protected/lib might be a good candidate.

My two penneth worth…

The logic part of an MVC app is described as a model. Now, in Yii terms, a typical model that interacts with a database extends CActiveRecord. Another type of model used for forms can be CActiveForm. So we can accept there are different types of models. For this reason, I use subdirectories in my models folder to seperate the type of model e.g.





//.. and so forth

In my main.php config, I then autoload each subdirectory





I have adopted this approach as it is similar to how Zend is structured and makes it easier to manage large applications that have a lot of classes.

The components folder is where all my prefigured compnents reside that I access via Yii::app()-[component name].

I’ll also include a vendor directory for other stuff like the Zend Framework or Doctrine.

Actually neither. What I mean by User defined include files is this:

I have a ‘slogan’ what I what to include in a couple of places. So I make a standard php file to include in the app.



$slogon1='My Stuff Is better than there stuff!';

$slogan2='Best stuff on the Internet';



Where in the directory structure would MyStuff.inc.php go?

Thanks All for the replies.

Since this looks like some configurable things, how about protected/config? There’s no real standard for things like these. You can put wherever you would search for it, when your customer wants a change in 1 year ;) .

I guess I was looking to help the programmer that comes after me, Heaven forbid I got ‘layed off’ :o

Currently I’m thinking of a directory up in near /css/ etc.

Thanks, Mike

I agree, simple strings can be placed in the main.php config file under the params array

'params' => array(

    'slogan1' => 'this is a slogan',

    'slogan2' => 'this is another slogan'


//.. access this is the app like so,

echo Yii::app()->params['slogan1'];

I was just thinking and agree that simple strings could/should go in the ./config/ directory. However I have an encryption class that I like to use, would that file also go in ./config/ ?

If you have a bunch of functions then why not create a class out of them and call them in your controllers like you would any other model?

Yes, but where to physically put the class file?


Uhm, o.k…? If you will search for texts in /css - go ahead. But should i be the programmer after you, i guarantee that i’ll never find your text configuration there ;)

About the encryption class: I’d rather put it unter components as it’s not a model. Don’t think too much about these decisions. You can easily relocate class files later, when you find out that protected/components gets to crowded.