1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Having a very odd issue... Uninitialized string offset: 0

Discussion in 'XenForo Development Discussions' started by Jaxel, Mar 2, 2011.

  1. Jaxel

    Jaxel Well-Known Member


    Below is my public controller...
    Code:
    <?php
    
    class EWRmedio_ControllerPublic_Media extends XenForo_ControllerPublic_Abstract
    {
        public $perms;
        public $slugs;
    
        public function actionIndex()
        {
            $mediaID = $this->_input->filterSingle('media_id', XenForo_Input::UINT);
    
            if (!$media = $this->getModelFromCache('EWRmedio_Model_Media')->getMediaByID($mediaID))
            {
                return $this->responseReroute(__CLASS__, 'Media');
            }
    
            $pid = '';
            if (!empty($this->slugs[1]))
            {
                if ($playlist = $this->getModelFromCache('EWRmedio_Model_Playlists')->getPlaylistByID($this->slugs[1]))
                {
                    $playlist = $this->getModelFromCache('EWRmedio_Model_Playlists')->getPlaylistWithMedia($playlist, $media);
                    $pid = '/'.$playlist['playlist_id'];
                }
            }
    
            $options = XenForo_Application::get('options');
            $start = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
            $stop = $options->EWRmedio_mediacount;
            $count = $this->getModelFromCache('EWRmedio_Model_Comments')->getCommentCount($media);
    
            $this->canonicalizeRequestUrl(XenForo_Link::buildPublicLink('media'.$pid, $media, array('page' => $start)));
            $this->canonicalizePageNumber($start, $stop, $count, 'media'.$pid, $media);
    
            $category = $this->getModelFromCache('EWRmedio_Model_Categories')->getCategoryByID($media['category_id']);
    
            $viewParams = array(
                'perms' => $this->perms,
                'start' => $start,
                'stop' => $stop,
                'playlist' => !empty($playlist) ? $playlist : false,
                'media' => $this->getModelFromCache('EWRmedio_Model_Media')->updateViews($media),
                'keywords' => $this->getModelFromCache('EWRmedio_Model_Media')->getKeywordLinks($media),
                'playlistList' => $this->getModelFromCache('EWRmedio_Model_Playlists')->getPlaylistByUserID(),
                'count' => $count,
                'comments' => $this->getModelFromCache('EWRmedio_Model_Comments')->getComments($media, $start, $stop),
                'breadCrumbs' => array_reverse($this->getModelFromCache('EWRmedio_Model_Lists')->getCrumbs($category)),
            );
    
            return $this->responseView('EWRmedio_ViewPublic_MediaView', 'EWRmedio_MediaView', $viewParams);
        }
    
        public function actionMedia()
        {
            $options = XenForo_Application::get('options');
    
            $viewParams = array(
                'perms' => $this->perms,
                'recentMedia' => $this->getModelFromCache('EWRmedio_Model_Lists')->getMediaList(1, $options->EWRmedio_recentcount, 'date', 'DESC'),
                'popularMedia' => $this->getModelFromCache('EWRmedio_Model_Lists')->getMediaList(1, $options->EWRmedio_popularcount, 'popular'),
                'sidebar' => $this->getModelFromCache('EWRmedio_Model_Parser')->parseSidebar(),
            );
    
            return $this->responseView('EWRmedio_ViewPublic_Media', 'EWRmedio_Media', $viewParams);
        }
    
        public function _preDispatch($action)
        {
            parent::_preDispatch($action);
    
            $this->perms = $this->getModelFromCache('EWRmedio_Model_Perms')->getPermissions();
            $this->slugs = explode('/', $this->_routeMatch->getMinorSection());
        }
    }
    On lines 12-15, it checks to see if a media ID is supplied in the URL. If it is is supplied and matches a media it continues on... THIS WORKS FINE...

    However, if it doesn't find a matching media, it reroutes to actionMedia(). This is where the error shows up. It seems to fail on line 64...
     
  2. Shadab

    Shadab Well-Known Member

    This means some code is accessing the 1st character of an empty string.
    This is happening in: XenForo/Model/User.php at line 798

    The source of that variable is: $this->_request->getUserParams()
    located in: XenForo/Controller.php at line 430

    Which indicates a "request" parameter name is empty. You need to check your Route Prefix class and see if any of the resolveAction*() method is being called with an empty string as the param name. That's your original source of the error.
     
    Kier likes this.
  3. Jaxel

    Jaxel Well-Known Member

    Thanks Shadab, as usual!

    I've been programming so much lately, but sometimes I still get lost in object oriented design...
     

Share This Page