TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Cannot access an Action via url (http://www.talkphp.com/general/4244-cannot-access-action-via-url.html)

Orc 05-07-2009 03:13 AM

Cannot access an Action via url
 
When you try to access an action in the url in Zend Framework: "http://www.example.com/index/action/" it doesn't seem to access the method in the Action Controller, what am I doing wrong? :-!

Village Idiot 05-07-2009 03:59 AM

Can you post the code?

Orc 05-07-2009 04:03 AM

Quote:

Originally Posted by Village Idiot (Post 23789)
Can you post the code?

Index.php
Code:

<?php
define("THIS_PAGE", "index");
define('BASE_PATH', realpath(dirname(__FILE__) . '../'));
define('APPLICATION_PATH', BASE_PATH . '/application');

set_include_path(BASE_PATH . '/library/incubator'
    . PATH_SEPARATOR .BASE_PATH . '/library'
    . PATH_SEPARATOR . get_include_path()
);

// APPLICATION_ENVIROMENT defines which config section is loaded
if(!defined('APPLICATION_ENVIRONMENT')) {
    define('APPLICATION_ENVIRONMENT', 'production');
}

require_once 'Zend/Application.php';

$application = new Zend_Application(APPLICATION_ENVIRONMENT,
    array(
        'bootstrap'=>array('path'=>APPLICATION_PATH.'/Bootstrap.php'),
        'autoloadernamespaces' => array('Zend', 'App')
    ));
$application->bootstrap();
$application->run();       
?>

application/controllers/IndexController.php
Code:

<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {

                echo "This will output though.";
           
    }

    public function indexAction()
    {
     
            echo "This won't output.";
           
    }


}

application/Bootstrap.php
Code:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

        protected $_config;

        public function _initConfig()
        {
                // config
                $this->_config = new Zend_Config_Ini(APPLICATION_PATH
                . '/configs/application.ini', APPLICATION_ENVIRONMENT);
                Zend_Registry::set('config', $this->_config);
                Zend_Registry::set('env', APPLICATION_ENVIRONMENT);

                // debugging
                if($this->_config->debug) {
                        error_reporting(E_ALL | E_STRICT);
                        ini_set('display_errors', 'on');
                }
        }

        protected function _initAutoload()
        {
                $moduleLoader = new Zend_Application_Module_Autoloader(array(
                'namespace' => '',
                'basePath' => APPLICATION_PATH));
                return $moduleLoader;
        }

        public function _initDB()
        {
                // Database
                if($this->_config->db) {
                        $dbAdapter = Zend_Db::factory($this->_config->db);
                        Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
                        Zend_Registry::set('dbAdapter', $dbAdapter);
                }
        }

        public function _initView()
        {
                // view and layout setup
                Zend_Layout::startMvc(APPLICATION_PATH . '/views/layouts');
                $view = Zend_Layout::getMvcInstance()->getView();
        }

        public function _initFrontController()
        {
                $frontController = Zend_Controller_Front::getInstance();
                $frontController->setControllerDirectory(APPLICATION_PATH .'/controllers');
                $frontController->setParam('env', APPLICATION_ENVIRONMENT);

                // action helpers
                Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
        }

        public function run()
        {
                $frontController = Zend_Controller_Front::getInstance();
                $frontController->dispatch();
        }


}

?>


Wildhoney 05-07-2009 11:34 AM

You're asking a lot here! :-) A lot of code to look through. Try accessing this URL though: http://www.example.com/index/index/

It looks like you're calling the action "action", which would be public function actionAction().


allworknoplay 05-07-2009 03:22 PM

Quote:

Originally Posted by Wildhoney (Post 23792)
You're asking a lot here! :-) A lot of code to look through. Try accessing this URL though: http://www.example.com/index/index/

It looks like you're calling the action "action", which would be public function actionAction().


WH,

What program are you using to create these quick diagrams?

Wildhoney 05-07-2009 03:38 PM

The Lovely YUML.me! :-)

allworknoplay 05-07-2009 03:44 PM

Quote:

Originally Posted by Wildhoney (Post 23800)
The Lovely YUML.me! :-)

Nice!!! I love it!!

Orc 05-07-2009 10:01 PM

Quote:

Originally Posted by Wildhoney (Post 23792)
You're asking a lot here! :-) A lot of code to look through. Try accessing this URL though: http://www.example.com/index/index/

It looks like you're calling the action "action", which would be public function actionAction().


I understand how it works, but the problem is when trying to actually access that action via the url.

Say I had a guestbook which linked to example.com/guestbook/

Thing is it wouldn't access the indexAction of the GuestbookController, nor would it access any other actions if I also applied those in the url.

Orc 05-08-2009 06:13 PM

Fixed it so far, had something to do with $this->layout()->content not in the layout script. :P

foobarph 05-11-2009 04:12 AM

so the layout thingy is the culprit. nice job orc.

*pokes wildhoney* haha! :)

Orc 05-11-2009 03:01 PM

Quote:

Originally Posted by foobarph (Post 23945)
so the layout thingy is the culprit. nice job orc.

*pokes wildhoney* haha! :)

Still learning. :-D


All times are GMT. The time now is 09:12 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0