Works In Dev Enviroment And Not In Production!

Hi All,

I have my site ready to be on production environment, so I have upladoed to the server all files and my surprise was when I fount out that some things doesn’t work!

Many links doesn’t find the correct url and I just don’t know why, I’m using modules and I don’t know if it’s a problem. For instance, I have the following CMenu:




$this->widget('zii.widgets.CMenu', array(

    'id'=>'cause-menu',

    'encodeLabel'=>false,

    'activateItems'=>true,

    'htmlOptions'=>array('class'=>'nav nav-list account-sidenav'),

    'items'=>array(

        array('label'=>'<i class="ico-eye-open"></i> Preview', 

              'url'=>array('/causes/cause/preview','id'=>$id),

              'itemOptions'=>array('id'=>'preview-item'),

        ),                                      

        array('label'=>'<i class="ico-edit"></i> Edit Cause', 

              'url'=>array('/causes/cause/update','id'=>$id),

              'itemOptions'=>array('id'=>'edit-item'),

        ),                        

        array('label'=>'<i class="ico-picture"></i> Images', 

              'url'=>array('/causes/cause/image', 'id'=>$id),

              'itemOptions'=>array('id'=>'images-item'),

        ),

        array('label'=>'<i class="ico-chat"></i> Comments', 

              'url'=>array('/causes/causecomment/index','id'=>$id),

              'itemOptions'=>array('id'=>'comments-item'),

        ),

    ),                            

));



The first three links, in the controller ‘cause’, works perfectly, but the link for the controller ‘causecontroller’ doesn’t work, showing the error:

Error 404

Unable to resolve the request "causes/causecomment/index/id/1".

This is what I have in my config/main:




'urlManager'=>array(

    'urlFormat'=>'path','showScriptName'=>false, 'caseSensitive'=>false,

    'rules'=>array(

        '<controller:\w+>/<id:\d+>'=>'<controller>/view',

        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

        //'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<module>/<controller>/<action>',

    ),

),



And in my .htaccess in my webroot:




RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



I have read the follow documentation:

Using search engine and user friendly urls

Using custom url rule classes

And I don’t know why this is happening because it works in my localhost!!! this happens in other places in my site, not only in the CMenu, also in a button:




$this->widget('bootstrap.widgets.TbButton', array(

    'buttonType'=>'link', 

    'url'=>Yii::app()->createUrl('/causes/causecomment/create', array('id'=>$model->id)),

    'type'=>'success', 

    'label'=>'Comment!',

    'size'=>'mini',

)); 



I don’t know why it can’t resolve the url for a different controller than ‘cause’.

Could someone help me with this? it’s really frustrating, thanks in advance.

There is a good chance you are moving from a Windows to Linux environment. When on Linux, letter casing matters.

For example, if your controller is CauseCommentController, your URL needs to be "/causes/causeComment/create". Also be sure to change the view folder name.

Hi chuntley,

thanks for your quick response, my localhost is under windows and on production I have a linux machine, but I also tried to change the letter cases, like:




array('label'=>'<i class="ico-chat"></i> Comments', 

              'url'=>array('/causes/causeComment/index','id'=>$id),

              'itemOptions'=>array('id'=>'comments-item'),

        ),



And it doesn’t work either. My view folder names are like this ‘causeComment’ and the controller, as you said, CauseCommentController, so all seems to be ok, any other suggestion?

Your long route paths indicate that you’re using modules - check your directory permissions. Also, if you’re going to hide index.php your .htaccess file should look as documented here. Good luck.

This is almost certainly a case sensitivity issue.

Make sure that your controller file is called CauseCommentController.php and the class is named CauseCommentController with those exact cases.

If you can link us to the live site, it might be easier to help.

Thank you both, I really appreciate your help.

As you can see in my first post, my .htaccess is exactly like in that link. I do use modules, the folder permissions are 705 and the files permissions are 604, which I think is correct.

I quite sure is not due to case sensitivity issue, I have checked many times and it seems ok:

CauseCommentController.php




class CauseCommentController extends Controller



If it was due to sensitivity issue, I guess the same thing would happen for the other links like:




array('label'=>'<i class="ico-eye-open"></i> Preview', 

              'url'=>array('/causes/cause/preview','id'=>$id),

              'itemOptions'=>array('id'=>'preview-item'),

        ),  



It’s strange to me that actions in CauseController works perfectly fine and from a view in cause folder calling to a CommentController action or another controller action diffenrent than CauseController doesn’t work. This is driving me nuts.

Thanks again

I have some news…

Just for testing, I have changed the controller’s name, where I had ‘CauseCommentController’, now I have ‘CommentController’, then my links:




array('label'=>'<i class="ico-chat"></i> Comments', 

              'url'=>array('/causes/comment/index','id'=>$id),

              'itemOptions'=>array('id'=>'comments-item'),

        ),



and… surprise!!! It works! I just don’t have any idea why keeping the other name doesn’t work, before changing every controller’s name I would like to find the solution, is this issue make any sense to you guys?

Thanks again for your responses