1
votes

I am a ZF beginner.

I am able to see http://localhost/square/public.

Then I added var/www/square/layouts and master.phtml in the directory. I have the following /var/www/square/application/configs/appliction.ini

When I visit the same page, it does not show anything.

What am I doing wrong here??

Thanks in advance.

application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
resources.layout.layout = "master"


[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Note:

  1. I set up a virtual host, so I can see it in http://square.localhost, if I take out resources.layout.layoutPath = APPLICATION_PATH "/layouts" resources.layout.layout = "master"

  2. When I echo APPLICATION_PATH in /var/www/square/application/modules/default/views/scripts/index/index.phtml , it outputs /var/www/square/application if I don't add

    resources.layout.layoutPath = APPLICATION_PATH "/layouts" resources.layout.layout = "master"

  3. I have given 666 to all files and 777 to all directories.

Update:

Error messages are followings

Fatal error: Uncaught exception 'Zend_Controller_Router_Exception' with message 'Route home is not defined' in /var/www/square/library/Zend/Controller/Router/Rewrite.php:318 Stack trace:

0 /var/www/square/library/Zend/Controller/Router/Rewrite.php(464): Zend_Controller_Router_Rewrite->getRoute('home')

1 /var/www/square/library/Zend/View/Helper/Url.php(49): Zend_Controller_Router_Rewrite->assemble(Array, 'home', false, true)

2 [internal function]: Zend_View_Helper_Url->url(Array, 'home')

3 /var/www/square/library/Zend/View/Abstract.php(342): call_user_func_array(Array, Array)

4 /var/www/square/application/layouts/master.phtml(15): Zend_View_Abstract->__call('url', Array)

5 /var/www/square/application/layouts/master.phtml(15): Zend_View->url(Array, 'home')

6 /var/www/square/library/Zend/View.php(108): include('/var/www/square...')

7 /var/www/square/library/Zend/View/Abstract.php(880): Zend_View->_run('/var/www/square...')

8 /var/www/square/library/Zend/Layout.php(796): Zend_View_Abstract->render('master.phtml')

9 in /var/www/square/library/Zend/Controller/Router/Rewrite.php on line 318

Update 2.

I am reading a book called Zendframework A Beginner Guide.

I have the following in master.phtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <base href="/" />
    <link rel="stylesheet" type="text/css" href="/css/master.css" />
  </head>
  <body>
    <div id="header">
      <div id="logo">
        <img src="/images/logo.gif" />
      </div>

      <div id="menu">
        <a href="<?php echo $this->url(array(), 'home'); ?>">HOME</a>
        <a href="<?php echo $this->url(array('page' => 'services'), 'static-content'); ?>">SERVICES</a>
        <a href="#">CONTACT</a>
      </div>
    </div>

    <div id="content">
      <?php echo $this->layout()->content ?>
    </div>

    <div id="footer">
      <p>Created with <a href="http://framework.zend.com/">Zend Framework</a>. Licensed under <a href="http://www.creativecommons.org/">Creative Commons</a>.</p>
    </div>    
  </body>
</html>

I commented out and it shows a page now.

 <a href="<?php // echo $this->url(array(), 'home'); ?>">HOME</a>
 <a href="<?php // echo $this->url(array('page' => 'services'), 'static-content'); ?>">SERVICES</a>
5

5 Answers

2
votes

blank white page means , there is some error but its hidden due to this config :

phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0 
resources.frontController.params.displayExceptions = 0 

could you please change to be like this :

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1 

and update your question with te error msg so we can help you :)

update this error indicate that zf trying to find route called home , routes deceleration usually saved in the application.ini , so i am not sure if this is ready made application or you are the programmer of this app

but try to look for something like :

$this->url(<!-- i am not sure what you might here but it usually array of module , controller , action --> , "home") ; 

in the master.phtml and again update your question once again with that code snippet

update 2

i am pretty sure if you had added these 3 lines to your application.ini and uncomment your code in the layout your problem would be solved

resources.router.routes.home.route = /home
resources.router.routes.home.defaults.module = default           
resources.router.routes.home.defaults.controller = index
resources.router.routes.home.defaults.action = index  
resources.router.routes.static-content.route = /content/:page              
resources.router.routes.static-content.defaults.module = default           
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.action = display           
1
votes

UPDATE:

I see you marked the answer but im not sure if you actually solved the issue, but it looks like youre simple missing a route definition for the routename home. If you define this you should be ok assuming you also have a route named static_content.


When I echo APPLICATION_PATH, it outputs /var/www/square/application without layout in .ini file.

The APPLICATION_PATH would never have the layout ... its simply the path to the application. on the filesystem. Also if youre not running this in a virtual host were APPLICATION_PATH/public is your DOCUMENT_ROOT you may need to set:

resources.frontController.baseUrl = "/square/public"

to make everythign work properly... by default it is assumed the APPLICATION_PATH/public is your DOCUMENT_ROOT.

Youre probably getting an error somewhere. Modify your index.php to use the development environment so you will see the errors and exceptions if there are any. Then update your questions with those details.

1
votes

I think I have this one figured out. The author wrote the book a little backwards. If you continue on in the chapter, the next few pages will explain how to create the home route as well as the static-content route and your application will once again work. This is just poor editing, I have bought 4 Zend Framework books and they all seem to have the same issues. It would be really nice if someone would take the time to actually try out / go through one of their own books before releasing broken code and screwing with peoples heads. Its a very discouraging thing :-|.

1
votes

update 2

I am pretty sure if you had added these 3 lines to your application.ini and uncomment your code in the layout your problem would be solved

    resources.router.routes.home.route = /home
    resources.router.routes.home.defaults.module = default           
    resources.router.routes.home.defaults.controller = index
    resources.router.routes.home.defaults.action = index  
    resources.router.routes.static-content.route = /content/:page              
    resources.router.routes.static-content.defaults.module = default           
    resources.router.routes.static-content.defaults.controller = static-content
    resources.router.routes.static-content.defaults.action = display      

worked for me :)
I had this problem, and figured out it should be related to de application.ini file.. but being a total noob in Zend, I couldn't figure out what to add all by myself.

0
votes

Shin, I'm sure you've figured out by now that the master.phtml you have assumes that you've gotten through the end of chapter 2 of the book. I made the same mistake of using the master.phtml from the companion website without comparing to the one posted in the book on that particular page which brought me to your post. :)

@prodigitalson:  isn't DOCUMENT_ROOT set to APPLICATION_PATH/../public?  not APPLICATION_PATH/public