Module Error 404 Unable to resolve the request

New to Yii, this has been driving me nuts. Thank you in advance.

When clicking my upvote or downvote button I get an error:

Unable to resolve the request "voting/vote/up/ownerModel/Lease/ownerId/1"

My view




      <?php Yii::app()->getModule('AVotingModule');

      $this->widget('application.modules.voting.widgets.AVoteButtons', array(

      'model'=>$model,

    ));?>



My widget




	/**

	 * Gets the upvote button for this votable model.

	 * @return string the HTML for the upvote button

	 */

	public function getUpvoteButton() {

		$htmlOptions = array("class" => $this->upvoteClass);

		$htmlOptions['id'] = $this->getId()."-upvote";

		$label = $this->upvoteLabel;

		if ($this->model->userHasVoted && $this->model->userVote->score == 1) {

			if (!isset($htmlOptions['class'])) {

				$htmlOptions['class'] = "";

			}

			$htmlOptions['class'] .= " active";

			$label = $this->upvotedLabel;

		}

	  //Create a behavior object.

        $obj=new AVotable;


      //Attach behavior

        $this->model->attachBehavior('AVotable',$obj);

        

		return CHtml::link($label, array("/voting/vote/up", "ownerModel" => $this->model->asa("AVotable")->getClassName(), "ownerId" => $this->model->asa("AVotable")->getId()),$htmlOptions);


	}



My VoteController




	/**

	 * Registers an upvote for the given model.

	 * @param string $ownerModel The class name of the owner model

	 * @param integer $ownerId The ID of the owner

	 */

	public function actionUp($ownerModel, $ownerId) {

		if (!Yii::app()->request->isPostRequest || !class_exists($ownerModel)) {

			throw new CHttpException(500,Yii::t("blocks","Invalid Request"));

		}

		$owner = $ownerModel::model()->findByPk($ownerId);

		if (!is_object($owner)) {

			throw new CHttpException(404,Yii::t("blocks","No such page"));

		}

		$result = ($owner->upVote() ? "upvoted" : ($owner->resetVote() ? "notvoted" : "ERROR"));

		if (Yii::app()->request->isAjaxRequest) {

			$response = new AJSONResponse();

			$response->score = $owner->totalVoteScore + 1;

			$response->totalUpvotes = $owner->totalUpvotes;

			$response->totalDownvotes = $owner->totalDownvotes; 

			$response->status = $result;

			$response->render();

			return;

		}

		else {

			if ($result === "ERROR") {

				Yii::app()->user->setFlash("error",Yii::t("blocks","<h3>Voting Error</h3><p>There was a problem registering your vote.</p>"));

			}

			else {

				Yii::app()->user->setFlash("success",Yii::t("blocks","<h3>Thanks for voting!</h3><p>Your vote was registerd, thanks.</p>"));

			}

			$this->redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : array("/site/index"));

		}



My config




	'import'=>array(

		'application.models.*',

	        'application.components.*',

                'application.modules.voting.models.*',        

                'application.modules.voting.components.*',

                'application.modules.voting.interfaces.*',

	),


	'modules'=>array(

		

		'AVoting'=>array(

		    'caseSensitive' => false,	    

		),



make sure in the rules function in the controller that the user has enough privileges to access actionUp.

Dear Friend,

Can you please give the following details?

What is the content of AvotingModule.php in the module ‘Avoting’.

Is there any need to call the method getModule.Because it is used to make a submodule inside a module.

If Avoting is the created module, The pathAlias should be ‘application.modules.Avoting.widgets.AVoteButtons’.

To import the contents of the module,it should be done in the init method of AvotingModule.php rather than in the main config file.

In main config file you have declared Avoting as a module. In URL request it is given as voting (the word before first forward slash).

Thanks for having a look…

My directory:

/modules

   /voting


        AVotingModule

When I change the main to no longer import I get error include AVotable.php no such file or directory. When I leave it, the widget works despite importing it in AVotingModule, shown below.

I removed the getModule in the view.

In the Url request in widgets/AVoteButtons I get same error if I change from voting to avoting: unable to resolve request "avoting/vote/up/ownerModel/Lease/ownerId/1"

AVotingModule.php




<?php




/**

 * Holds functionality related to voting.

 * Votes can be attached to other models and are managed via the vote controller.

 */


class AVotingModule extends CWebModule

{

	/**

	 * The name of the votes table

	 * Defaults to "votes"

	 * @var string

	 */

	public $voteTable = "votes";


	/**

	 * Whether users must be logged in or not to vote, defaults to true.

	 * @var boolean

	 */

	public $requiresLogin = true;


	/**

	 * Holds an array of items to show in the main menu

	 */

	public $mainMenu = array(

			array('label'=>'Home', 'url'=>array('/reviews/review/admin'))

		);	

	

	

	public function init()

	{


		// import the module-level models and components

		$this->setImport(array(

			'avoting.models.*',

			'avoting.components.*',

			'avoting.interfaces.*',

		));

	}


	public function beforeControllerAction($controller, $action)

	{

		if(parent::beforeControllerAction($controller, $action))

		{

			// this method is called before any module controller action is performed

			// you may place customized code here

			return true;

		}

		else

			return false;

	}

}



widget/AVoteButtons




<?php

/**

 * Displays customisable vote buttons for voteable items.

 * @package packages.voting.widgets

 */

class AVoteButtons extends CWidget {

	/**

	 * Holds the voteable model

	 * @var CActiveRecord

	 */

 	public $model;

 	

	/**

	 * The label that should appear on the upvote button

	 * @var string

	 */

	public $upvoteLabel = "Upvote";


	/**

	 * The label that should appear on the downvote button

	 * @var string

	 */

	public $downvoteLabel = "Downvote";


	/**

	 * The label that should appear on the upvote button when the use has up voted.

	 * @var string

	 */

	public $upvotedLabel = "Upvoted";


	/**

	 * The label that should appear on the downvote button when the user has downvoted.

	 * @var string

	 */

	public $downvotedLabel = "Downvoted";


	/**

	 * The template to use when displaying the vote buttons.

	 * The following tokens are recognised:

	 * <li>{upvote} - The upvote button</li>

	 * <li>{downvote} - The downvote button</li>

	 * <li>{summary} - The summary tag</li>

	 * @var string

	 */

	public $template = "{upvote} {downvote} {summary}";

	/**

	 * The CSS class for the upvote button

	 * @var string

	 */

	public $upvoteClass = "upvote button";

	/**

	 * The CSS class for the downvote button

	 * @var string

	 */

	public $downvoteClass = "downvote button";


	/**

	 * The CSS class for the summary span

	 * @var string

	 */

	public $summaryClass = "score";


	/**

	 * The template for the summary tag.

	 * The following tokens are recognised:

	 * <li>{upvotes} - The number of upvotes for this item</li>

	 * <li>{downvotes} - The number of downvotes for this item</li>

	 * <li>{score} - The total number of votes for this item</li>

	 * @var string

	 */

	public $summaryTemplate = '<span class="score" title="{upvotes} liked it, {downvotes} didn\'t like it">{score}</span>';

	/**

	 * The htmlOptions for the container tag

	 * @var array

	 */

	public $htmlOptions = array();


	/**

	 * The options for the jQuery plugin

	 * @var array

	 */

	public $options = array();


	/**

	 * The tag name for the container.

	 * Defaults to "div".

	 * @var string

	 */

	public $tagName = "div";


	/**

	 * Displays the vote buttons and reviews summary.

	 */

	public function run() {

		$id = $this->getId();

		$htmlOptions = $this->htmlOptions;

		$htmlOptions['id'] = $id;

		echo CHtml::tag($this->tagName,$htmlOptions,strtr($this->template,array(

				"{summary}" => $this->getSummary(),

				"{upvote}" => $this->getUpvoteButton(),

				"{downvote}" => $this->getDownvoteButton(),

				)));

		$data = array();

		if (Yii::app()->request->enableCsrfValidation) {

			$data[Yii::app()->request->csrfTokenName] = Yii::app()->request->csrfToken;

		}

		$data= CJavaScript::encode($data);

		$options = array(

				"selectors" => array(

						"upvote" => "a.".implode(".",explode(" ",$this->upvoteClass)),

						"downvote" => "a.".implode(".",explode(" ",$this->downvoteClass)),

						"summary" => "span.".implode(".",explode(" ",$this->summaryClass))

					),

				"postData" => array(),

				"labels" => array(

						"upvote" => $this->upvoteLabel,

						"downvote" => $this->downvoteLabel,

						"upvoted" => $this->upvotedLabel,

						"downvoted" => $this->downvotedLabel,

						"summary" => $this->summaryTemplate

					)

			);

		if (Yii::app()->request->enableCsrfValidation) {

			$options['postData'][Yii::app()->request->csrfTokenName] = Yii::app()->request->csrfToken;

		}

		$options = CMap::mergeArray($options,$this->options);

		if (function_exists("json_encode")) {

			$options = json_encode($options);

		}

		else {

			$options = CJSON::encode($options);

		}

		$script = "$('#$id').AVoteButtons($options);";

		$this->registerScripts();

		Yii::app()->clientScript->registerScript(__CLASS__."#".$id,$script);

	}

	

	/**

	 * Gets the upvote button for this votable model.

	 * @return string the HTML for the upvote button

	 */

	public function getUpvoteButton() {

		$htmlOptions = array("class" => $this->upvoteClass);

		$htmlOptions['id'] = $this->getId()."-upvote";

		$label = $this->upvoteLabel;

		if ($this->model->userHasVoted && $this->model->userVote->score == 1) {

			if (!isset($htmlOptions['class'])) {

				$htmlOptions['class'] = "";

			}

			$htmlOptions['class'] .= " active";

			$label = $this->upvotedLabel;

		}

	  //Create a behavior object.

        $obj=new AVotable;


      //Attach behavior

        $this->model->attachBehavior('AVotable',$obj);

        

		return CHtml::link($label, array("/avoting/vote/up", "ownerModel" => $this->model->asa("AVotable")->getClassName(), "ownerId" => $this->model->asa("AVotable")->getId()),$htmlOptions);


	}


	/**

	 * Gets the downvote button for this votable model.

	 * @return string the HTML for the downvote button

	 */

	public function getDownvoteButton() {

		$htmlOptions = array("class" => $this->downvoteClass);

		$htmlOptions['id'] = $this->getId()."-downvote";

		$label = $this->downvoteLabel;

		if ($this->model->userHasVoted && $this->model->userVote->score == -1) {

			if (!isset($htmlOptions['class'])) {

				$htmlOptions['class'] = "";

			}

			$htmlOptions['class'] .= " active";

			$label = $this->downvotedLabel;

		}

		return CHtml::link($label, array("/avoting/vote/down", "ownerModel" => $this->model->asa("AVotable")->getClassName(), "ownerId" => $this->model->asa("AVotable")->getId()),$htmlOptions);

	}

	

	/**

	 * Gets the review summary for this votable model.

	 * @return string the summary of votes for this model

	 */

	public function getSummary() {

		return strtr($this->summaryTemplate, array(

			"{score}" => $this->model->totalVoteScore + 1,

			"{upvotes}" => $this->model->totalUpvotes,

			"{downvotes}" => $this->model->totalDownvotes,


		));


	}


	/**

	 * Registers the required scripts

	 */

	public static function registerScripts() {

		$baseUrl = Yii::app()->assetManager->publish(dirname(__FILE__)."/assets/".__CLASS__);

		Yii::app()->clientScript->registerScriptFile($baseUrl."/AVoteButtons.js");


	}

}	



When you add a module in main config file, the main application will look for

the a directory with same name in ‘modules’ directory.

In your case the ‘voting’ is only directory in ‘modules’.

Directly place the ‘Avoting’ directory inside the ‘modules’ directory.

Put the Avoting.module.php inside the ‘Avoting’ directory.

Create the ‘extension’ folder inside the ‘Avoting’ directory.

Put the widget inside the extensions folder.

create the directories ‘controllers’,‘views’,‘components’ and ‘models’ inside ‘Avoting’

view file should look like the following.




<?php 

      $this->widget('application.modules.Avoting.extensions.widgets.AVoteButtons', array(

      'model'=>$model,

    ));?>



The whole idea is getting rid of directory ‘voting’.

I hope it will help you.

REMEMBER TO ADD MODULES IN MAIN CONFIG FILE


'modules'=>array('AVoting')

Most Error 404 Unable to resolve the request “xxx/xxxx” is due to the path parsing issue. The system could not locate the controller or action name. In linux system it’s case sensitive. for example, you controller name is UserManagerController, and you may able to run the code like

"index.php/usermanager/create" in windows environment, but it may bring the Error 404 in linux system, so you have to change the url to

"index.php/userManager/create" or "index.php/UserManager/create" to catch the correct controller name. The first initial is not matter lower case or not.

Error 404

Unable to resolve the request "Xyz".

i also configure ‘caseSensitive’ => false, in main.php file.

need your help