TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-20-2009, 05:36 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Zend Framework

Ye, I'm having some troubles with Zend framework.
More specificly the view files.

I have this:
index.phtml
Code:
<h1 align="center">
    Hello, Zend Framework MVC!
</h1>

<?php echo 'Testing'; ?>
It outputs "Hello, Zend Framework MVC", but not the "Testing" part.
I tried other stuff, but it's almost like the PHP won't evaluate or be proccessed by the server.

I'm using WAMP on localhost btw.

When I check the source code on the page, I even see the PHP code there, but with the php tags and the echo part aswell. Like an HTML comment.. or something.

Any clues?


Also, another problem I'm having is when creating the .htaccess file. Whenever I have an access file, it gives me 500 server error, no matter what's in the file. Do I have to enable mod_rewrite or anything? Why is it giving me that error?

Thanks!
__________________
Tanax is offline  
Reply With Quote
Old 03-20-2009, 06:20 PM   #2 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Ye, I'm having some troubles with Zend framework.
More specificly the view files.

I have this:
index.phtml
Code:
<h1 align="center">
    Hello, Zend Framework MVC!
</h1>

<?php echo 'Testing'; ?>
It outputs "Hello, Zend Framework MVC", but not the "Testing" part.
I tried other stuff, but it's almost like the PHP won't evaluate or be proccessed by the server.

I'm using WAMP on localhost btw.

When I check the source code on the page, I even see the PHP code there, but with the php tags and the echo part aswell. Like an HTML comment.. or something.

Any clues?


Also, another problem I'm having is when creating the .htaccess file. Whenever I have an access file, it gives me 500 server error, no matter what's in the file. Do I have to enable mod_rewrite or anything? Why is it giving me that error?

Thanks!

Ok, your issue is that your webserver, I assume IIS? Is not interpreting your code as PHP. That's why the PHP tags are being printed out.

Perhaps it doesn't know about .phtml?

Try renaming your file to: index.php

And see what happens...
allworknoplay is offline  
Reply With Quote
Old 03-20-2009, 06:29 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
Ok, your issue is that your webserver, I assume IIS? Is not interpreting your code as PHP. That's why the PHP tags are being printed out.

Perhaps it doesn't know about .phtml?

Try renaming your file to: index.php

And see what happens...
IIS? No I'm using WAMP.
And yea, I guess, but how to solve that?
PHP tags aren't actually printed on the page, only visible in the sourcecode of the page.

I don't know, it should work :S
I can't rename it to .php, because then Zend won't recognize it so it won't work..
__________________
Tanax is offline  
Reply With Quote
Old 03-20-2009, 06:46 PM   #4 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
IIS? No I'm using WAMP.
And yea, I guess, but how to solve that?
PHP tags aren't actually printed on the page, only visible in the sourcecode of the page.

I don't know, it should work :S
I can't rename it to .php, because then Zend won't recognize it so it won't work..

oh my bad....everytime I think windows, I think IIS...

Ok, so in your apache config called: httpd.conf

You need to add this:

AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml


so do a search for "AddType application" and you should find the area to add it.

then restart your apache...
allworknoplay is offline  
Reply With Quote
Old 03-20-2009, 07:36 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
oh my bad....everytime I think windows, I think IIS...

Ok, so in your apache config called: httpd.conf

You need to add this:

AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml


so do a search for "AddType application" and you should find the area to add it.

then restart your apache...
Hehe, it's okay!
Thanks for that.

I edited this file:
C:\wamp\bin\apache\apache2.2.8\conf

and added the phtml extension.

This was already there:
Code:
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
so I just added this below:
Code:
AddType application/x-httpd-php .phtml
and then restarted.
However, the problem still persists :S
I still can't use PHP in the .phtml files.


Although, I solved the rewrite issue, cause I read your post in the other Zend thread about having to enable it in apache, and I found it, and enabled it, so that part works now!

Only the .phtml issue left to solve
__________________
Tanax is offline  
Reply With Quote
Old 03-20-2009, 07:37 PM   #6 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Although, I solved the rewrite issue, cause I read your post in the other Zend thread about having to enable it in apache, and I found it, and enabled it, so that part works now!

Only the .phtml issue left to solve
Ok can you copy and paste your code exactly so I can take a look?
allworknoplay is offline  
Reply With Quote
Old 03-20-2009, 07:43 PM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I'm using the exact copy-paste from quick guide except I added a variable to the view object.

IndexController.php
php Code:
<?php
// application/controllers/IndexController.php

/**
 * IndexController is the default controller for this application
 *
 * Notice that we do not have to require 'Zend/Controller/Action.php', this
 * is because our application is using "autoloading" in the bootstrap.
 *
 * @see [url]http://framework.zend.com/manual/en/zend.loader.html#zend.loader.load.autoload[/url]
 */

class IndexController extends Zend_Controller_Action
{
    /**
     * The "index" action is the default action for all controllers. This
     * will be the landing page of your application.
     *
     * Assuming the default route and default router, this action is dispatched
     * via the following urls:
     *   /
     *   /index/
     *   /index/index
     *
     * @return void
     */

    public function indexAction()
    {
        $this->view->text = 'Hi';
    }
}

index.phtml
php Code:
<h1 align="center">
    Hello, Zend Framework MVC!
</h1>

<?= $this->text ?>

And I've also tried it without the shorttags, thinking that was the problem, but didn't work with regular php echo style either..
__________________
Tanax is offline  
Reply With Quote
Old 03-20-2009, 07:47 PM   #8 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Oh, and here's some screenshots:

In the browser:
http://img6.imageshack.us/img6/5051/zenderr1.jpg

Sourcecode from browser:
http://img6.imageshack.us/img6/9505/zenderr2.jpg

As you see, I can see the whole php code in the sourcecode, which I'm not really supposed to do if it were processed by PHPserver..
__________________
Tanax is offline  
Reply With Quote
Old 03-20-2009, 07:48 PM   #9 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
index.phtml
php Code:
<h1 align="center">
    Hello, Zend Framework MVC!
</h1>

<?= $this->text ?>

And I've also tried it without the shorttags, thinking that was the problem, but didn't work with regular php echo style either..
Ok, I was just going to say, it could be the short tags.

I know that PHP6 is discontinuing the short tags, I'm not sure if PHP5 supports it or not....

Anyways, can you create a simple test file and see if the PHP works?

Create a file called: test.php

And in it just type this:


Code:
<?php

$test = 'test';

echo $test;

?>
Let me know what you get...what we want to do is forget about the Zend framework. We need to see if Apache itself is configured correctly for PHP..
allworknoplay is offline  
Reply With Quote
Old 03-20-2009, 07:51 PM   #10 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yes yes, the PHP works great outside of the .phtml file. Otherwise the index bootstrap wouldn't really work, now would it?

PHP5 supports shorttags.
Check out the screenshots in my previous post for visual of the error.
__________________
Tanax is offline  
Reply With Quote
Old 03-20-2009, 07:59 PM   #11 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Yes yes, the PHP works great outside of the .phtml file. Otherwise the index bootstrap wouldn't really work, now would it?

PHP5 supports shorttags.
Check out the screenshots in my previous post for visual of the error.

Hmm ok, let me get my framework configured and see how mine turns out. I'm working on something else right now so give me about 2 hours and I'll get back to you!!!
allworknoplay is offline  
Reply With Quote
Old 03-20-2009, 11:36 PM   #12 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

How is your htaccess configured? Because you're in windows it might be a problem.

I am having issues right now getting mine to work, so I have to backtrack and thoroughly read the instructions...
allworknoplay is offline  
Reply With Quote
Old 03-20-2009, 11:47 PM   #13 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

It looks like the one in the quick start guide.

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
The rewrite works great though. I can access controllers and their respectivly functions by changing the url to localhost/controllername/functionname and it works great.

It's just the part with the viewfiles that does get processed by PHP(or something - I don't know, I'm just guessing that, since the PHP tags and code gets put on the page like a HTML comment - again, see the screenshots).

Ah, we'll figure it out, hehe
__________________
Tanax is offline  
Reply With Quote
Old 03-20-2009, 11:55 PM   #14 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
It looks like the one in the quick start guide.

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
The rewrite works great though. I can access controllers and their respectivly functions by changing the url to localhost/controllername/functionname and it works great.

It's just the part with the viewfiles that does get processed by PHP(or something - I don't know, I'm just guessing that, since the PHP tags and code gets put on the page like a HTML comment - again, see the screenshots).

Ah, we'll figure it out, hehe
Take a look at your apache config and see where it looks for .htaccess.

See, in linux, it's called .htaccess. But with Windows you might have to call it htaccess.txt and then tell your config to look for that instead of the default .htaccess.

Also check your log files and see what the error_log says....
allworknoplay is offline  
Reply With Quote
Old 03-20-2009, 11:59 PM   #15 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
Take a look at your apache config and see where it looks for .htaccess.

See, in linux, it's called .htaccess. But with Windows you might have to call it htaccess.txt and then tell your config to look for that instead of the default .htaccess.

Also check your log files and see what the error_log says....
But as I said, the .htaccess file has nothing to do with this as it is working perfectly well and is doing everything it is supposed to do..
And yes, in Windows we call it .htaccess aswell as you do in LINUX.

I checked it, it didn't have any error log about this
__________________
Tanax is offline  
Reply With Quote
Old 03-21-2009, 12:07 AM   #16 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
But as I said, the .htaccess file has nothing to do with this as it is working perfectly well and is doing everything it is supposed to do..
And yes, in Windows we call it .htaccess aswell as you do in LINUX.

I checked it, it didn't have any error log about this
Ok, well I am currently recompiling my apache because mod_rewrite isn't working for me right now.

Once I can get my own test bed to work, I'll see what we can do about yours!
allworknoplay is offline  
Reply With Quote
Old 03-21-2009, 07:31 AM   #17 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Find this line:

Code:
short_open_tag = Off
in your php.ini file, and change it to "On", then restart apache. That should do it.

PS: it was not required that you added the .phtml extension to the .htaccess file as the views (templates) are internally parsed by Zend (the template contents are evaluated by PHP, not directly accessed via the web browser). Also, you should use:

PHP Code:
<?php echo 'stuff'?>
instead of the short form, so that you will not have problems when going live with the project. If it's a test project it's ok, but you might get very angry if the server you're going to move the project to doesn't have short_open_tag on (and that is quite usual).
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 03-21-2009, 11:32 AM   #18 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Find this line:

Code:
short_open_tag = Off
in your php.ini file, and change it to "On", then restart apache. That should do it.

PS: it was not required that you added the .phtml extension to the .htaccess file as the views (templates) are internally parsed by Zend (the template contents are evaluated by PHP, not directly accessed via the web browser). Also, you should use:

PHP Code:
<?php echo 'stuff'?>
instead of the short form, so that you will not have problems when going live with the project. If it's a test project it's ok, but you might get very angry if the server you're going to move the project to doesn't have short_open_tag on (and that is quite usual).
Ye, I found that line before and set it to On and restarted the Apache. However, the problem still persists.

I didn't add .phtml extension to .htaccess. I added it to httpd.conf in apache folder.
And yes, I tried it with regular PHP tags, but that didn't work either..
__________________
Tanax is offline  
Reply With Quote
Old 03-21-2009, 01:14 PM   #19 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Is the PHP extension even loaded in Apache? You must have a line in your httpd.conf file that says something like this:

Code:
LoadModule php5_module "c:/webserver/bin/php/php5.2.9-1/php5apache2_2.dll"
This is what I have on my Windows box, running WAMP server. PHP will not work if it's not "injected" into the Apache engine first. If it is, then something must be wrong with that dll file (probably corrupt). Check the Apache error log if the line above is present (and, obviously, uncommented) in your httpd.conf file.

PS: I was referring to the httpd.conf file in the post before.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 03-21-2009, 03:48 PM   #20 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Is the PHP extension even loaded in Apache? You must have a line in your httpd.conf file that says something like this:

Code:
LoadModule php5_module "c:/webserver/bin/php/php5.2.9-1/php5apache2_2.dll"
This is what I have on my Windows box, running WAMP server. PHP will not work if it's not "injected" into the Apache engine first. If it is, then something must be wrong with that dll file (probably corrupt). Check the Apache error log if the line above is present (and, obviously, uncommented) in your httpd.conf file.

PS: I was referring to the httpd.conf file in the post before.
I think so..
I found this line in httpd.conf
Code:
LoadModule php5_module "c:/wamp/bin/php/php5.2.6/php5apache2_2.dll"
And the thing is, I don't think that there's something wrong with that, because PHP files works great with PHP. I have numerous other projects on this localhost server(that aren't using Zend Framework) and they work perfectly well.

Also, if PHP didn't work, how come the index file redirects every request to the correct controller?

Ah I see! My bad then
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Zend Studio code completion framework Devels General 1 09-06-2008 05:04 PM
Zend Framework in Action (book) freenity The Lounge 2 04-06-2008 11:12 AM
Zend Framework 1.5 Devels Libraries & Extensions 5 03-17-2008 03:06 PM
Zend Framework - questions questions abiko Advanced PHP Programming 4 02-29-2008 12:46 AM
Zend Framework Karl General 13 10-24-2007 04:19 PM


All times are GMT. The time now is 08:22 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design