I have a big project coming up. Time to brush up my PHP and mySQL skills. With all the frameworks and IDEs out there, I am leaving Dreamweaver (even though Dreamweaver CS5 has some good feature) and getting on a PHP IDE.

Zend Studio is what I chose just because it’s more supported and more industrially known. it looks to be more scalable for bigger commercial project so I might as well learn that.  After spending 2 hours fiddling with it and typing code, I can see there is some learning curve (plus the learning of Zend framework), but in general it looks really handy.

Glitches:

1. To directly connect to a remote MySql database in Zend, you need to enable remote access in your MySQL settings for your PC.  The easiest way is to add a row to mysql.user table for your PC (use % as Host name)  and the db user  in PhpMyAdmin. Add database specific privilege to the user@%. Use the change password field in the user privilege UI interface to change password for real. (copying hashed password in the user table doesn’t work.

In Zend, the connection setting should be:

database: db_name
url: jdbc:mysql://hostingbox.hostingsite.com:3306/db_name  (I have a virtual hosting site. use hosting company site instead of a domain name)
user name: db_user
password: db_password.

2. Cannot test/run project. always says 404 even when I export the project. Turns out I cannot write files to the Program Files (x86)/Zend/Apache2/htdocs folder even in a text editor.

http://forums.zend.com/viewtopic.php?f=59&t=5045

run Zend as Administrator. Now I can see progress bar flying by when I export the application. The files are copied to the htdocs folder. running standalone php files within the test project works. Running public/index.php still gives error

Internal Server Error

To configure Zend Server to run a Zend Framework application:

1.Define a virtual host on Zend Server that will point to the new project’s public directory:
2.Find the full path to your project’s public directory.
3.This is listed in the location field in the project’s properties. To see it, in PHP Explorer view right-click the public directory and select Properties | Resources.
4Open your Apache configuration file (in most cases it will be httpd.conf and located in your Apache installation directory). Go to the end of the file and add the following code:

Listen 10089
<VirtualHost *:10089>
DocumentRoot “DOCUMENT_ROOT”
<Directory “DOCUMENT_ROOT”>
Order allow,deny
Allow from all
AllowOverride all
</Directory>
</VirtualHost>

1. Replace “DOCUMENT_ROOT” with the full path to the public directory, enclosed in double quotes (“DOCUMENT_ROOT”).
Replace the port number with a unique port number dedicated to this Virtual Host. The port number (10089) has to be the same value for “Listen” and “VirtualHost”.
2 Zend Framework’s MVC implementation makes use of the Front Controller pattern. You must therefore rewrite all incoming requests (except those for static resources, which your application need not handle) to a single script that will initialize the FrontController and route the request. If you’re using mod_rewrite for the Apache web server, create the file /public/.htaccess  (already setup )
3. Restart your Web server from the command line (windows user can use the Apache Monitor tool).

I did all that, and it didn’t work. Then I looked at my server error log (not the error log within Zend studio) and the error was:

[28-Feb-2011 16:27:45] PHP Warning:  require_once(library/meetingForm.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in C:\Program Files (x86)\Zend\Apache2\htdocs\Test1\application\controllers\IndexController.php on line 3
[28-Feb-2011 16:27:45] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'library/meetingForm.php' (include_path='C:\Program Files (x86)\Zend\Apache2\htdocs\Test1\application/../library;C:\Program Files (x86)\Zend\Apache2\htdocs\Test1\library;.;C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library') in C:\Program Files (x86)\Zend\Apache2\htdocs\Test1\application\controllers\IndexController.php on line 3

 

I removed the “library/” string in the meetingForm.php require line since the including path already has library included. This time the page loads

I removed the lines added to httpd.conf. and start working on the form. It was loading properly, but no dojo interaction. I added main.phtml. Now it’s giving me

An error occurred
Application error

[28-Feb-2011 17:44:03] PHP Fatal error:  Class 'Zend_Application_Bootstrap_Bootstrap' not found in C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php on line 3

 

===========

3/1 I’m frustrated by how little video tutorials I can find on Zend Studio. I’m trying Eclipse next.
Unless your Java is 64bit also, don’t download the 64bit Eclipse. You’ll get Java class not found error several times.

Add Zend Framework to Eclipse
http://inchoo.net/tools/how-to-work-with-svn-and-zend-framewrok-in-eclipse-pdt/

 

I’m having serious problem with configuring Apache. It doesn’t seem to read the httpd.conf file!  Let’s turn off UAC and IIS and see! (My IIS is already off)

http://perfect-it-solutions.blogspot.com/2007/12/disable-uac-and-iis.html

OMG!! that’s it!! I am writing a separate blog on this!

==========

I having been following the first tutorial on this page (starting from the source package he provided)
http://www.killerphp.com/zend-framework/videos/

I set the vitural host on port 10085 to be DocumentRoot “C:\Program Files (x86)\Zend\Apache2\htdocs\ArticleManager\html”

Now, http://localhost:10085/ shows “No input file specified”

I noticed the index.php  line 26 Zend_Layout::startMvc($option); was using $option instead of $options. Corrected that.

change .htaccess from

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

to

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

now the MVC is working correctly. http://localhost:10085/index and http://localhost:10085/article behave accordingly! Finally, it matches the tutorial!

 

=====

to summarize, to add a new controller in a Zend framework project, add a MyControler.php to the class folder, extends Zend_Controller_Action, define public function indexAction(), then add a folder “My” under views/scripts/ and add index.phtml to the My folder.

for a url: http://localhost:10085/article/new, the browser is passing the following into your index.php

[“controller”]=> string(7) “article”
[“action”]=> string(3) “new”
[“module”]=>
string(7) “default”

=============

Another really good tutorial that is for Zend Framework 1.10 and above: http://akrabat.com/zend-framework-tutorial/ It starts from the skeleton Zend Application.

my Zend experience
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *