0

**Edit2: Core.php was not found because Bootstrap.php needed Core.php included require_once 'C:\wamp\www\PhpProject1\application\Core\Core.php'; Solved my Problem **


I am using zendframework and i created a new folder with file Core/Core.php for my functions that i will use in my controllers and elsewhere. But when i try to test a function in my Core.php nothing will show up. I think i am calling the core.php incorrectly but im not sure what the error is.

application/controllers/

IndexController.php

class IndexController extends Zend_Controller_Action
{

     public function init()
    {
         $this->tournamentAction();
    }

   public function indexAction(){          

   }

    public function tournamentAction()
  {            
        $bleh = new Core();
        $this->view->ha = $bleh->yo();
        $this->renderScript('tournament/index.phtml');            
    }    
}

application/Core/

Core.php

class Core{

    public function init(){

    }

    public function indexAction(){

    }
    public function yo(){
        $text = 'This is my function Yo';
        return $text;
    }

application/views/scripts/tournament/ index.phtml

$this->ha;
echo "hello";

Edit: Error reporting is nice ha! This is the error i get.

 ! ) Fatal error: Class 'Core' not found in C:\wamp\www\PhpProject1\application\controllers\IndexController.php on line 19
Call Stack
#   Time    Memory  Function    Location
1   0.0006  678944  {main}( )   ..\index.php:0
2   0.0275  3090632 Zend_Application->run( )    ..\index.php:26
3   0.0275  3090632 Zend_Application_Bootstrap_Bootstrap->run( )    ..\Application.php:366
4   0.0275  3090728 Zend_Controller_Front->dispatch( )  ..\Bootstrap.php:97
5   0.0446  4801056 Zend_Controller_Dispatcher_Standard->dispatch( )    ..\Front.php:954
6   0.0456  4823424 Zend_Controller_Action->__construct( )  ..\Standard.php:268
7   0.0547  5211576 IndexController->init( )    ..\Action.php:133
8   0.0547  5211576 IndexController->tournamentAction( )    ..\IndexController.php:8
5
  • You never echo or print the $this->ha. Commented Oct 15, 2011 at 17:33
  • I just made that change but it still did not print anything. Commented Oct 15, 2011 at 17:36
  • Does it get printed when you do: echo $this->ha; die;? Commented Oct 15, 2011 at 17:40
  • No it does not display anything for echo or print_r Commented Oct 15, 2011 at 17:45
  • Please tick the correct answer if any help has been given by one of these. Commented Oct 25, 2011 at 11:27

2 Answers 2

1

You problem is that the autoloader can't find your Core class.

Usually I structure my application by using a library folder where all my models and tools end.

In your case, I would create in the library folder a folder called MyProject, inside it you can put your Core.php class, put you'll have to correct it's name which leads to :

library/MyProject/Core.php

class MyProject_Core{

public function init(){

}

public function indexAction(){

}
public function yo(){
    $text = 'This is my function Yo';
    return $text;
}

Of course you'd to call your class this way:

$coreInstance = new MyProject_Core();

Put this function in your application/Bootstrap.php :

protected function _initAutoload()
{
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('MyProject_');
    $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath' => APPLICATION_PATH));
    return $autoloader;
}

Then the Zend_Loader should find your class whithout any problem.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for specific tools/logic in the library folder and the autoloader, but I think models should stay within the models or module/models folder
Yes, I admit this is a personnal choice that could be discussed but I often consider my model as library part since they doesn't often direct end user action.
0

In your view you do:

$this->ha; // this doesn't do anything without an echo / print

Also you said:

I think i am calling the core.php incorrectly but im not sure what the error is.

If that's the case you should enable error reporting.

Add this at the top of your bootstrap file:

error_reporting(E_ALL | E_STRICT);
ini_set("display_errors", 1);

1 Comment

Haha thanks the error reporting will help nicely. I edited my question to the output of the error. It seems it cannot find my Core.php class. Am i calling it incorrectly or do i need to change settings for it to be seen? Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.