+ Reply to Thread
Results 1 to 6 of 6

Thread: Path error when rendering views

  1. #1
    Drac is offline Junior Member
    Join Date
    Jun 2008
    Posts
    7

    Default Path error when rendering views

    I've been trying to render a different view than the default, so here's what I've done.

    /game/applications/controllers/AccountController.php:
    [PHP]
    //snip...
    $view = new Zend_View();
    $view->setScriptPath("/game/application/views/scripts/account");
    echo $view->render('test.phtml');[/PHP]

    /game/application/views/scripts/account/test.phtml:
    [PHP]
    <?php
    echo("hello world...");
    [/PHP]

    But when I navigate to AccountController I get:

    Code:
    Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'test.phtml' not found in path
    (/game/application/views/scripts/account/)'
    in /var/www/game/library/Zend/View/Abstract.php:857
    I've been trying to figure it out for three days straight now, and I still don't know what the problem is. Anyone able to help me out?

  2. #2
    bennell is offline Junior Member
    Join Date
    May 2008
    Posts
    16

    Default

    I think it's looking for the file as an absolute path. Try ...
    Code:
    $view->setScriptPath("/var/www/game/application/views/scripts/account");

  3. #3
    Drac is offline Junior Member
    Join Date
    Jun 2008
    Posts
    7

    Default

    Hmm, strange, now I get
    Code:
    Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'test/index.phtml' not found in path 
    (../application/views/scripts/)' in
     /var/www/game/library/Zend/View/Abstract.php:857
    It seems to be looking for the default script, which I haven't provided. When I do provide it in the default location, it renders that default script - even though a print_r($view->getScriptPaths()) reveals the path as
    [PHP]Array ( [0] => /var/www/game/application/views/scripts/account/ ) [/PHP]
    But that's definitely not where it's looking. :/

  4. #4
    Drac is offline Junior Member
    Join Date
    Jun 2008
    Posts
    7

    Default

    Hate to bump, but I still haven't managed to get this working. Anyone got any ideas?

  5. #5
    Tekerson is offline Senior Member
    Join Date
    Jul 2008
    Posts
    288

    Default

    You're creating a new Zend_View object in the action, but there is already a view created automatically. It is rendered at the end of the action function. You can suggest the view script it should run by giving instructions to the viewRenderer helper. eg.
    Code:
    $this->_helpers->viewRenderer->setScriptAction('test');
    (Zend Framework: Documentation)
    This will cause the "test.phtml" file to be rendered, assuming it is in the same directory as the default script.
    Brenton Alker
    PHP Developer - Brisbane, Australia

    blog.tekerson.com | twitter.com/tekerson | brenton.mp

  6. #6
    wingsof5r is offline Junior Member
    Join Date
    May 2010
    Posts
    4

    Default I got similar issue? Any one got solution for the same.

    Quote Originally Posted by Drac View Post
    I've been trying to render a different view than the default, so here's what I've done.

    /game/applications/controllers/AccountController.php:
    [PHP]
    //snip...
    $view = new Zend_View();
    $view->setScriptPath("/game/application/views/scripts/account");
    echo $view->render('test.phtml');[/PHP]

    /game/application/views/scripts/account/test.phtml:
    [PHP]
    <?php
    echo("hello world...");
    [/PHP]

    But when I navigate to AccountController I get:

    Code:
    Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'test.phtml' not found in path
    (/game/application/views/scripts/account/)'
    in /var/www/game/library/Zend/View/Abstract.php:857
    I've been trying to figure it out for three days straight now, and I still don't know what the problem is. Anyone able to help me out?

    ===============
    public function updateAction()
    {
    $view = new Zend_View();
    $script_path = APPLICATION_PATH.'/views/scripts/account/';
    $view->setScriptPath($script_path);
    $view->render('update');

    }

    I am trying to call update action manually under my account controller as above.
    It is not rendering.

    If the view script , is not in default standard path i.e view/scripts/<controller>/action.phtml, then how do i render the view?

    For ex:

    public function newsAction()
    {
    //If the the phtml is not in the default location
    $script_path = APPLICATION_PATH;
    $this->view->addScriptPath('/var/www/html/loudbit/application/');
    print_r($this->view->getScriptPath());
    $this->render('news');
    }

    The above also not working. How do we make this renders possible? Please help me, trying from 2 days.

+ Reply to Thread

Similar Threads

  1. Views not rendering correctly
    By retrodans in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 08-08-2010, 11:38 AM
  2. How To setup Layout and Views path
    By bluesapphire in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 10-29-2009, 05:39 PM
  3. Set different path for the views directory in a module
    By tvhoang in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 01-10-2009, 06:01 AM
  4. Rendering views
    By matches in forum General Q&A on Zend Framework
    Replies: 3
    Last Post: 11-06-2008, 09:53 PM
  5. Rendering views
    By smartcoderin in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 04-01-2008, 11:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts