Yii Framework Forum: Yii Routing - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Routing directory problem Rate Topic: -----

#1 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 07:13 AM

Hi,

I have directory 'upload/download' in my project root. And I add controller/action - UploadController and actionDownload on it.
What I want is when user hit the url '/myproject/upload/download' to execute controller action instead to open directory 'upload/downlpoad'. I have to keep the same names.

My structure is:
  • project root
  • ->upload
  • -->download
  • ->protected
  • -->controllers ... and so on.

I try with urlManager but without success.
I am not shure is it possible or how to do it?
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,520
  • Joined: 04-March 10
  • Location:UK

Posted 15 April 2014 - 07:27 AM

This is probably something that needs to be done in a .htaccess file. If you only allow direct access to files (not directories), then Yii's routing should kick in automatically.

Can you show your existing .htaccess file?
0

#3 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 07:30 AM

I have only this in my .htaccess file
Options +FollowSymLinks
IndexIgnore */*
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

0

#4 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,520
  • Joined: 04-March 10
  • Location:UK

Posted 15 April 2014 - 07:38 AM

Try removing this condition:

RewriteCond %{REQUEST_FILENAME} !-d

1

#5 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 07:47 AM

When I remove it everything crashes.
None of the links work.
Even jquery is not loaded.
0

#6 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 08:04 AM

View PostKeith, on 15 April 2014 - 07:38 AM, said:

Try removing this condition:

RewriteCond %{REQUEST_FILENAME} !-d



Ok, it's working when I remove the condition but application can't find jquery file I try to load.
0

#7 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,520
  • Joined: 04-March 10
  • Location:UK

Posted 15 April 2014 - 08:07 AM

Okay, put that back in :D .

Your best course of action is probably to put a separate .htaccess file inside the upload/download directory. I've done something similar for on demand thumbnail generation.

You'll need to experiment with the content of the file. Something like this might work:

Options -Indexes

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /

# If the requested file does not exist...
RewriteCond %{REQUEST_FILENAME} !-f

# forward to index.php
RewriteRule . index.php

</IfModule>


I'm not too familiar with .htaccess rules though, so I suspect you'll need to do some more work on it.
1

#8 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 08:10 AM

View PostGogo, on 15 April 2014 - 08:04 AM, said:

Ok, it's working when I remove the condition but application can't find jquery file I try to load.


The problem was that I load jquery with 'registerCoreScript'. I change it to load from my file I put in application and now works. I don't now why Yii::app()->clientScript->registerCoreScript('jquery') doesn't work.
0

#9 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,520
  • Joined: 04-March 10
  • Location:UK

Posted 15 April 2014 - 08:11 AM

I'd be concerned that other things will break if something so central to Yii does.
0

#10 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 08:17 AM

Yeah, you are right. I will try to do it with separate .htaccess file and see what will happen.
0

#11 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 16 April 2014 - 07:48 PM

View PostGogo, on 15 April 2014 - 07:13 AM, said:

Hi,

I have directory 'upload/download' in my project root. And I add controller/action - UploadController and actionDownload on it.
What I want is when user hit the url '/myproject/upload/download' to execute controller action instead to open directory 'upload/downlpoad'. I have to keep the same names.

My structure is:
  • project root
  • ->upload
  • -->download
  • ->protected
  • -->controllers ... and so on.

I try with urlManager but without success.
I am not shure is it possible or how to do it?


To expand on something said above: I think the problem is that you have a directory AND a controller called 'upload' The .htaccess first looks to see is the user is requesting a file or directory that exists...THAN sends off to index.php.

Try changing the name of your 'upload' directory, or the structure to something like
root
  +-assests
  +-files
  | +-upload
  | +-download
  +-protected
  + etc 


Another option that I have seen quite often is to store the files in protected then use a proxy action to send to user. The link tag would call the controllerId/actionId passing an identifier to which file to send.
Do, or do not. There is no 'try.' Jedi Master Yoda
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users