[Solved] Cassetmanager.basepath Not Valid Error

Hi,

I am a newbie to yii and i cant figure out the following error :




 CAssetManager.basePath "/home/roy/projects/isml/source/portal/assets" is invalid. Please make sure the directory exists and is writable by the Web server process.


/home/roy/projects/isml/source/framework/web/CAssetManager.php(138)


126     }

127 

128     /**

129      * Sets the root directory storing published asset files.

130      * @param string $value the root directory storing published asset files

131      * @throws CException if the base path is invalid

132      */

133     public function setBasePath($value)

134     {

135         if(($basePath=realpath($value))!==false && is_dir($basePath) && is_writable($basePath))

136             $this->_basePath=$basePath;

137         else

138             throw new CException(Yii::t('yii','CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.',

139                 array('{path}'=>$value)));

140     }

141 

142     /**

143      * @return string the base url that the published asset files can be accessed.

144      * Note, the ending slashes are stripped off. Defaults to '/AppBaseUrl/assets'.

145      */

146     public function getBaseUrl()

147     {

148         if($this->_baseUrl===null)

149         {

150             $request=Yii::app()->getRequest();


Stack Trace

#0 	

+

 /home/roy/projects/isml/source/framework/web/CAssetManager.php(123): CAssetManager->setBasePath("/home/roy/projects/isml/source/portal/assets")

#1 	

+

 /home/roy/projects/isml/source/framework/web/CAssetManager.php(217): CAssetManager->getBasePath()

#2 	

+

 /home/roy/projects/isml/source/framework/zii/widgets/grid/CGridView.php(325): CAssetManager->publish("/home/roy/projects/isml/source/framework/zii/widgets/assets")

#3 	

+

 /home/roy/projects/isml/source/framework/web/CBaseController.php(147): CGridView->init()

#4 	

+

 /home/roy/projects/isml/source/framework/web/CBaseController.php(172): CBaseController->createWidget("zii.widgets.grid.CGridView", array("id" => "notifications-grid", "dataProvider" => CActiveDataProvider, "cssFile" => "/isml/source/portal/media/css/gridview.css", "enablePagination" => false, ...))

#5 	

–

 /home/roy/projects/isml/source/portal/protected/views/user/notifications.php(74): CBaseController->widget("zii.widgets.grid.CGridView", array("id" => "notifications-grid", "dataProvider" => CActiveDataProvider, "cssFile" => "/isml/source/portal/media/css/gridview.css", "enablePagination" => false, ...))


69                                     'header' => '<div class="listactioncolumn">Action</div>',

70                                     'htmlOptions' => array('class' => 'listactioncolumn'),

71                                     'template' => ' {Edit}',

72                                     'buttons' => array(),

73                                     ),

74                             ),));

75                ?>

76                 <div class="grid-view-footer">

77                     <div class="paginationholder">

78                         <div id="pagination">

79                             <?php //$widget->renderPager(); ?>


#6 	

+

 /home/roy/projects/isml/source/framework/web/CBaseController.php(126): require("/home/roy/projects/isml/source/portal/protected/views/user/notif...")

#7 	

+

 /home/roy/projects/isml/source/framework/web/CBaseController.php(95): CBaseController->renderInternal("/home/roy/projects/isml/source/portal/protected/views/user/notif...", array("model" => Notifications), true)

#8 	

+

 /home/roy/projects/isml/source/framework/web/CController.php(869): CBaseController->renderFile("/home/roy/projects/isml/source/portal/protected/views/user/notif...", array("model" => Notifications), true)

#9 	

+

 /home/roy/projects/isml/source/framework/web/CController.php(782): CController->renderPartial("notifications", array("model" => Notifications), true)

#10 	

–

 /home/roy/projects/isml/source/portal/protected/controllers/UserController.php(180): CController->render("notifications", array("model" => Notifications))


175         if($key) {

176             $model->notificationText = $key;

177         }

178         echo "-----------".$key;

179         $this -> layout = 'main';

180         $this->render('notifications' ,array('model' => $model));            

181         

182     }

183 

184     //Notifications

185     public function actionNewnotification() {


#11 	

+

 /home/roy/projects/isml/source/framework/web/actions/CInlineAction.php(49): UserController->actionNotifications()

#12 	

+

 /home/roy/projects/isml/source/framework/web/CController.php(308): CInlineAction->runWithParams(array())

#13 	

+

 /home/roy/projects/isml/source/framework/web/filters/CFilterChain.php(133): CController->runAction(CInlineAction)

#14 	

+

 /home/roy/projects/isml/source/framework/web/filters/CFilter.php(40): CFilterChain->run()

#15 	

+

 /home/roy/projects/isml/source/framework/web/CController.php(1145): CFilter->filter(CFilterChain)

#16 	

+

 /home/roy/projects/isml/source/framework/web/filters/CInlineFilter.php(58): CController->filterAccessControl(CFilterChain)

#17 	

+

 /home/roy/projects/isml/source/framework/web/filters/CFilterChain.php(130): CInlineFilter->filter(CFilterChain)

#18 	

+

 /home/roy/projects/isml/source/framework/web/CController.php(291): CFilterChain->run()

#19 	

+

 /home/roy/projects/isml/source/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array("accessControl"))

#20 	

+

 /home/roy/projects/isml/source/framework/web/CWebApplication.php(282): CController->run("notifications")

#21 	

+

 /home/roy/projects/isml/source/framework/web/CWebApplication.php(141): CWebApplication->runController("user/notifications")

#22 	

+

 /home/roy/projects/isml/source/framework/base/CApplication.php(169): CWebApplication->processRequest()

#23 	

–

 /home/roy/projects/isml/source/portal/index.php(13): CApplication->run()


08 defined('YII_DEBUG') or define('YII_DEBUG',true);

09 // specify how many levels of call stack should be shown in each log message

10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

11 

12 require_once($yii);

13 Yii::createWebApplication($config)->run();




My controller function is this :




//Notifications

	public function actionNotifications() {

		$model = new Notifications;

        

		$key = Yii::app()->request->getQuery('key');

        if($key) {

            $model->notificationText = $key;

        }

        $this -> layout = 'main';

        $this->render('notifications' ,array('model' => $model));			

		

	}




Model :




<?php


/**

 * This is the model class for table "mobsrv_notification".

 *

 * The followings are the available columns in table 'mobsrv_notification':

 * @property 	integer 	$notificationId

 * @property 	string 		$notificationText

 * @property 	datetime 	$notificationDate

 * @property 	tinyinteger	$status

 * @property 	integer 	$createdBy

 * @property 	string 		$createdDate

 * @property 	integer 	$modifiedBy

 * @property 	string 		$modifiedDate

 */

class Notifications extends CActiveRecord

{

    /**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return Notifications the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'mobsrv_notification';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('notificationText', 'required'),

			array('createdDate, modifiedDate', 'safe'),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('notificationText', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'notificationText' 	=> 'Notification Title',

			'createdDate' 		=> 'Notification Created Date',

			'modifiedDate' 		=> 'Notification Modified Date'

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('notificationText',$this->notificationText,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

	  public function notificationList() {

            $criteria=new CDbCriteria;

            $criteria->compare('notificationText',$this->notificationText,true);

            //$sort = new CSort;

			//$sort->attributes = array('*');

			//$pagination = new CPagination;

	

			if ($this->notificationText) {

				

				//$sort->params = array(

				//	'key' => $this->notificationText,

				//	'page' => Yii::app()->request->getQuery('page', '0'),

				//);

				//$pagination->params = array(

				//	'key' => $this->notificationText,

				//	'sort' => Yii::app()->request->getQuery('sort', 'notificationId'),

				//);

			}

			//$sort->defaultOrder = 'news_id';

            return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

			//'sort' => $sort,

			//'pagination' => $pagination,

		));

        }




        

}



View :




<?php 

                $widget = $this->widget('zii.widgets.grid.CGridView', array(

                            'id' => 'notifications-grid',

                            'dataProvider' => $model->notificationList(),

                            'cssFile' => Yii::app()->baseUrl . '/media/css/gridview.css',

                            'enablePagination' => false,

                            'ajaxUpdate' => false,

                            'emptyText' => 'No results found.',

                            'template' => '{items}',

                            // 'pager' => array(

                            //     'class' => 'LinkPager',

                            //     'cssFile' => false,

                            //     'header' => false,

                            //     'firstPageLabel' => 'First',

                            //     'prevPageLabel' => 'Previous',

                            //     'nextPageLabel' => 'Next',

                            //     'lastPageLabel' => 'Last',

                            // ),

                            'columns' => array(

                                array(

                                        'name' => 'id',

                                        'type' => 'raw',

                                        'header' => '#',

                                        'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',

                                    ),

                                array(

                                    'name' => 'notificationText',

                                    'type' => 'raw',

                                    'header' => 'Title <div class="sorticon">' . CHtml::image(Yii::app()->request->baseUrl . "/media/images/sort.png") . '</div>',

                                    'value' => '$data->notificationText',

                                ),                                

                                array(

                                    'name' => 'createdDate',

                                    'type' => 'raw',

                                    'header' => 'Created On <div class="sorticon">' . CHtml::image(Yii::app()->request->baseUrl . "/media/images/sort.png") . '</div>',

                                    'value' => '$data->createdDate',

                                ),

                                array(

                                    'class' => 'CButtonColumn',

                                    'header' => '<div class="listactioncolumn">Action</div>',

                                    'htmlOptions' => array('class' => 'listactioncolumn'),

                                    'template' => ' {Edit}',

                                    'buttons' => array(),

                                    ),

                            ),));

               ?>

                <div class="grid-view-footer">

                    <div class="paginationholder">

                        <div id="pagination">

                            <?php //$widget->renderPager(); ?>

                        </div>

                    </div>

                </div>



There was error with the following part earlier, but now its gone and this new error pops up







$model = new Notifications;




Any help is greatly appreciated. …

Thanks

Roy

Make sure you have a folder named assets in your web root and that it is writable. Set the permissions to 0777 for now.

Yes the assets folder was already there. I updated the code through SVN and after that everything went haywire… I manually tried to add the permission but i guess in linux you have to do it through command prompt. Did that and solved the issue… Thankyou for your help… :)

I tend not to commit runtime writable directories to source control. Git doesn’t keep the permissions that you set, I don’t know if this is the same with SVN.

I have an init script which is checked into source control and can be run the first time a repository is cloned.

An example from one project in setup/init.sh:




#!/bin/bash


cd "$(dirname ${BASH_SOURCE[0]})"


cd ..


mkdir --mode=0777 ./protected/runtime

mkdir --mode=0777 ./www/assets

chmod 0777 ./www/files/images

mkdir --mode=0777 ./www/files/images/versions


echo "DONE"



It creates directories that aren’t in source control and changes the permissions of those that are. I’m not particularly proficient with bash, so I suspect there are better options.

Very cool man…Ive only started to use SVN and still learning its features…

I guess from your below code, i just need mkdir --mode=0777 ./www/assets part i guess…

Thanks a lot for your help. Ill have a dig into this automated permission control part meanwhile…