Hello all,

I am a seasoned developer and have been building apps with Cake for
some time. Today I came up against a bug that I cannot figure out -
Cake just STOPPED working. I'm using the 1.2 beta on php 5.x and all
has been well throughout this dev. However, I moved a block of code
into the AppController file to make it available to everything and it
was a bit buggy. So, I moved it back to where it came from... that's
all. Now I am getting a fatal error:

Call to a member function findByUri() on a non-object in C:\Program
Files\Zend\Apache2\htdocs\app\app_controller.php on line 52

In spite of this:

var $uses = array('Page', 'User', 'PageModule', 'News', 'Location',
'Content', 'UserLocation');

...and in spite of the fact it was working fine before! As I said, I
know what I'm doing and I cannot understand why Cake isn't creating an
instance of the "Page"  model - or any classes for that matter: the
problem exists for components as well. Here is the (abridged)
beforeRender() method I'm using for this:

                function beforeRender()
                {
                    // see if there's any $bodytext set to pass into the page 
along
with the dynamic title
                    $q = $this->Page->findByUri(str_replace('/', '', $this-
>params['url']['url'])); // line 52
                    if (!empty($q)) {
                        $q = $this->Content->findById($q['Page']['content_id']);
                        $this->set('pagetitle', $q['Content']['title']);
                        $this->set('bodytext', $q['Content']['body']);
                    }
                 }

I am desperate to get to the bottom of this... has anyone experienced
this before? I really need a hand here! I have (somewhat desperately!)
reinstalled Cake's Core, restarted my machine (in the hope that PHP
itself was the culprit!) and looked everywhere for the cause of the
bug. No joy. The full AppController file is pasted at the bottom of
this message.

Looking forward to your responses,

Matt

-----------------------------------------------------------------------
<?php
    class AppController extends Controller
    {
        var $components = array('ObAuth', 'Email', 'Notification',
'Submenu', 'Cookie', 'RequestHandler', 'Session');
        var $uses = array('Page', 'User', 'PageModule', 'News',
'Location', 'Content', 'UserLocation');
        var $helpers = array('Html', 'Form', 'Ajax', 'Session',
'Javascript', 'Crumb');

        var $defaultLocation = 'London';
        var $defaultExpiry = 31556926;

        function __construct()
                {
                    parent::__construct();
                        // Import this [abstract] class WITHOUT instantiating 
an object
                        App::import('model', 'LookupModel');
                }

        function beforeFilter()
                {
                    if ($this->referer() != '/users/login' && $this->here != 
'/users/
login')
                        $this->Session->write('UberReferer', $this->here);

                        // Only instantiate if it doesn't already exist..
                        if (!isset($this->ObAuth)) $this->ObAuth = new 
ObAuthComponent();

                        // Just in case it hasn't been started up (Which it 
hasn't it
seems, at beforeFilter() stage)
                        $this->ObAuth->startup($this);

                        if (!$loc = $this->Cookie->read('userLocation')) {
                $q = $this->Location->findByName($this-
>defaultLocation);
                $locationId = $q['Location']['id'];
                        } else {
                            $locationId = $loc;
                        }

            // hard code user data until we have some test users
            if (!$this->ObAuth->getUserId()) {
                $this->userLocation = $locationId;
            } else {
                $q = $this->User->findById($this->ObAuth-
>getUserId());
                $this->userLocation = !empty($q['User']
['location_id']) ? $q['User']['location_id'] : $locationId;
            }

            // set user id for the app
            $this->userId = $this->ObAuth->getUserId();
                }

                function beforeRender()
                {
                    // see if there's any $bodytext set to pass into the page 
along
with the dynamic title
                    $q = $this->Page->findByUri(str_replace('/', '', $this-
>params['url']['url']));
                    if (!empty($q)) {
                        $q = $this->Content->findById($q['Page']['content_id']);
                        $this->set('pagetitle', $q['Content']['title']);
                        $this->set('bodytext', $q['Content']['body']);
                    }
                    // App-wide admin protection function. Override it if you 
want..
            if (eregi('admin_', $this->params['action'])) {

                $this->layout = 'admin';
                $this->ObAuth->lock('admin');
            }

                    // set the modules that are available for this section
                    if (isset($this->params['controller']) && $this-
>params['action'] == 'index' && array_key_exists(low($this-
>params['controller']), $this->PageModule->modules))
                $this->modules = $this->PageModule->modules[low($this-
>params['controller'])];

            // Pass in the authentication component to allow all pages
to access user/session data
            $this->set('authObject', $this->ObAuth);

            // Oh go on let's give them a session too
            $this->set('session', $this->Session);

            $this->set('route', @$this->params['controller']);

                        if (!isset($this->Submenu)) $this->Submenu = new
SubmenuComponent();

                        $this->set('sectionMenu', 
$this->Submenu->submenuItems());

                         //pr($this->params);
                    $this->set('params', $this->params);

                    if ($this->params['action'] == 'index' &&
array_key_exists(low($this->params['controller']), $this->PageModule-
>modules)) {

                    $this->set('modules', $this->PageModule->modules[low($this-
>params['controller'])]);

                if ($storedModules = $this->Cookie->read(low($this-
>params['controller']) .'ModulePrefs')) {
                    $this->data = unserialize($storedModules);
                } else {
                    // display the default modules
                    $this->data['PageModule']['modules'] = array(0, 1,
2, 3, 4);
                    $this->Cookie->write(low($this-
>params['controller']) .'ModulePrefs', serialize($this-
>data['PageModule']['modules']), (mktime()+3600));
                }

                $this->data[low($this-
>params['controller']) .'_content'] = array();

                // this is temporary: an array of exclusions that will
gradually grow as things are built::
                $exclusions = array('news');

                foreach ($this->data['PageModule']['modules'] as $key
=> $module) {

                    if (!in_array($this->PageModule->modules[low($this-
>params['controller'])][$module], $exclusions))  {
                        $moduleContentVar = $this->PageModule-
>modules[low($this->params['controller'])][$module] .'_content';
                            $this->data[low($this-
>params['controller']) .'_content'][$this->PageModule-
>modules[low($this->params['controller'])][$module]] =
                            'This is dynamic data for the '. $this-
>PageModule->modules[low($this->params['controller'])][$module] .'
module';
                    }
                }
                    }
                }
    }
?>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to