Problems Using Modules


I want to put the “blog yii demo” as a module into my website but I’ve just come across a PHP warning: “include(Post.php): failed to open stream: No such file or directory”. This is the code of the controller:

117     public function actionIndex()

118     {

119         $criteria=new CDbCriteria(array(

120             'condition'=>'status='.Post::STATUS_PUBLISHED,

121             'order'=>'update_time DESC',

122             'with'=>'commentCount',

123         ));

124         if(isset($_GET['tag']))

125             $criteria->addSearchCondition('tags',$_GET['tag']);

What should I do? Please note that I do have the class "Post" inside the "models" folder

Hi since you created this as a module, make sure that in modules/modulename/model/ there is a Post.php model file. But based on your statement you already put Post.php in models dir.

Here is another thing to check.

class ModuleNameModule extends CWebModule


	public $defaultController ="Post"; //or the name of your controller

	public function init()


		// this method is called when the module is being created

		// you may place code here to customize the module or the application

		// import the module-level models and components



			'branch.models.*', // make sure that you have this




you have to do some work to convert the application to a module, You can create a new blog module and then copy the files in that module.

It worked! Thanks a lot. However, another problem has arisen: I would like to use the layout of the main application, not the layout of the module. How can I solve this?

Hi here is what should be in your Controller

class ModuleController extends Controller {


     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

     * using two-column layout. See 'protected/views/layouts/column2.php'.


    public $layout = '//layouts/column2';

You can change this.

many thanks, it worked!