简体   繁体   中英

Zend Framework 1.12 - Action Controller not working

I am new to Zend framework and I have installed zend frameworkd 1.12. It seems to be running find except for the fact the the views don't read the command specify in the action controller.

I have tested this with two controllers one is the index controller and second a created controller through zf command. here is the code.

<?php

class TestController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        //echo "Please read this";
    }

    public function indexAction()
    {
        echo 1;
    }

}

Here is the link to the view for this controller (just to be sure that not the problem)

Zend_Projects/test1/application/views/scripts/test/index.phtml

and the output of the controller:

-->> View script for controller Test and script/action name index

It does not add the 1 or any string from the echo command

Can anyone tell me why the controller action is not be read by the view?

Please any sort of help is appreciated and I apologize in advance if this is a stupid question.

Best of Regards

If you want to output an value from your Action inside your view, you have to to pass it with:

public function indexAction()
{
   $this->view->mytext = 'Test';
}

now inside your .phtml script:

<?php echo $this->mytext; ?> 

As per the comments to the question

You dont have to copy anything php file to public folder except for index.php also make sure there is a .htaccess file present in public folder and mod_rewrite is enabled in apache. That is if you are using apache (otherwise you should use url rewriting method of the server that you are using.) If this all sounds greek to you and I assume you dont know greek then refer http://framework.zend.com/manual/1.12/en/zend.controller.router.html

if all this is already done then there might be a problem with router. refer http://framework.zend.com/manual/1.12/en/project-structure.rewrite.html

The key is that you dont call the actual phtml file in a browser, that is done by the application. The browser always calls index.php in public folder which is done via rewriting urls. the index.php file initializes the zend application and runs it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM