Zend Framework - URL parameter not detected?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Zend Framework - URL parameter not detected?

Post by DaveTheAve »

Well, I've just started following IBM's "Understanding the Zend Framework" series. I realize it was designed for Zend Framework 0.1.4; thus, I had to add the no norouteAction() and have it call indexAction. The problem i'm having is on the Controllers, actions, and the URL section. I can access 127.0.0.1/framework/ and it works fine, however, if I access 127.0.0.1/framework/user I don't get a "This is the indexAction." message I'm suppose to be getting.

Yes, I did copy and past right; yes, i did name the files right. I feel that this could be a .htaccess issue.

My current .htaccess is:
Options +FollowSymLinks
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|php)$ index.php
php_value include_path ".;libs/ZendFramework/library"
Note: I had to include Options +FollowSymLinks or the rewrite engine would fail with a 403 error message for some stupid reason.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try adding

Code: Select all

RewriteBase /framework
to your htaccess
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

I just tried that code several times each with different methods, it didn't work; Thank you for your help though.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Whoops, didnt realize something..

What exactly are you putting in the framework folder? Typically your bootstrap should go in the root directory.
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

127.0.0.1/framework/ folder contains:

Code: Select all

libs/
 |
 ---> ZendFramework/
          |
          --->demos;documentation;incubator;library;scripts;tests;etc.... (Your basic) framework 0.2.0 files
views/
controllers/
.htaccess
index.php
and my include_path has "libs/ZendFramework/library" in it so I don't have to worry about failing include for the framework.
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

Here is my bootstrap if that helps at all:

Code: Select all

<?php
/* Place Zend Framework in include path */
ini_set('include_path',ini_get('include_path') . ';' . 'libs/ZendFramework/library');

/* Load Zend Framework */
require_once('Zend.php');

/* Set Zend_View */
Zend::loadClass('Zend_View');
$view = new Zend_View();
$view->setScriptPath('views');
Zend::register('view', $view);

/* Set Zend_Controller_Front */
Zend::loadClass('Zend_Controller_Front');
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('controllers');
$controller->dispatch();
and my .htaccess is now:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

Note: Just added view to the registry, 30sex ago.
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

FIXED IT!

Note: The only reason I'm posting the solution is for other people to know what to do.

If you are running Zend Framework from a subdirectory you MUST patch your Zend_Controller_Router. However, I want my Zend Framework to remain vanilla so I added an extra 2 lines (+ 1 comment line) to my bootstrap file. Note: This could was tested with Zend Framework 0.2.0. I was told it works in eariler versions and was also told there is word this might be fixed in the next framework release.

The code to add to the bootstrap file:

Code: Select all

/* Patch Zend_Controller_Router to use subdirectorys */
$url = explode ( "/", $_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = str_replace($url[1], "", $_SERVER['REQUEST_URI']);
Last edited by DaveTheAve on Fri Dec 01, 2006 3:43 pm, edited 1 time in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

DaveTheAve wrote:Zend Framework 0.2.0.
*fixed
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

No you didn't, I caught it before you and fixed it. :P Thanks though.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Strange... I saw your post that said 1.2.0 and my post that said 0.2.0 on the same page...

:wink:
Post Reply