SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast boardy's Avatar
    Join Date
    Feb 2007
    Location
    Lincoln, UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Strange problem with Zend Framework

    Hi,

    I'm using the Zend Framework to build a CMS for a client. I have a blog system attached to this also but for some reason I can't get the route to work for displaying the content for an article.

    I am getting the following error in my debug log -

    Code:
    2008-07-09T22:52:20+01:00 CRIT (2): section is not specified
    This is the code for the routes and index.php -

    PHP Code:
    <?php
        
    require_once('Zend/Loader.php');
        
    Zend_Loader::registerAutoload();

        
    // setup the application logger
        
    $logger = new Zend_Log(new Zend_Log_Writer_Null());

        try {
            
    $email "adam.boardman@devariosdesign.com";
            
    $writer = new EmailLogger($email);
            
    $writer->addFilter(new Zend_Log_Filter_Priority(Zend_Log::CRIT));
            
    $logger->addWriter($writer);

            
    // load the application configuration
            
    $configFile '';
            if (isset(
    $_SERVER['APP_CONFIG_FILE']))
                
    $configFile basename($_SERVER['APP_CONFIG_FILE']);

            if (
    strlen($configFile) == 0)
                
    $configFile 'settings.ini';

            
    $configSection '';
            if(isset(
    $_SERVER['APP_CONFIG_SECTION']))
                
    $configSection basename($_SERVER['APP_CONFIG_SECTION']);

            if (
    strlen($configSection) == 0)
                
    $configSection 'production';

            
    $config = new Zend_Config_Ini('../' $configFile$configSection);
            
    Zend_Registry::set('config'$config);

            
    // Alter the application logger
            
    $logger->addWriter(new Zend_Log_Writer_Stream($config->logging->file));
            
    $writer->setEmail($config->logging->email);

            
    Zend_Registry::set('logger'$logger);

            
    // connect to the database
            
    $params = array('host'     => $config->database->hostname,
                            
    'username' => $config->database->username,
                            
    'password' => $config->database->password,
                            
    'dbname'   => $config->database->database);

            
    $db Zend_Db::factory($config->database->type$params);
            
    $db->getConnection();

            
    Zend_Registry::set('db'$db);


            
    // setup application authentication
            
    $auth Zend_Auth::getInstance();
            
    $auth->setStorage(new Zend_Auth_Storage_Session());

            
    // handle the user request
            
    $controller Zend_Controller_Front::getInstance();
            
    $controller->setControllerDirectory($config->paths->base .
                                                
    '/include/Controllers');
            
    $controller->registerPlugin(new CustomControllerAclManager($auth));

            
    // setup the view renderer
            
    $vr = new Zend_Controller_Action_Helper_ViewRenderer();
            
    $vr->setView(new Templater());
            
    $vr->setViewSuffix('tpl');
            
    Zend_Controller_Action_HelperBroker::addHelper($vr);

            
    // setup the route for the user home pages
            
    $route = new Zend_Controller_Router_Route('user/:username/:action/*',
                                                      array(
    'controller' => 'user',
                                                              
    'action' => 'index'));

            
    $controller->getRouter()->addRoute('user'$route);

            
    // setup the route for viewing blog posts
            
    $route = new Zend_Controller_Router_Route('user/:username/view/:url/*',
                                                      array(
    'controller' => 'user',
                                                              
    'action' => 'view'));

            
    $controller->getRouter()->addRoute('post'$route);

            
    // setup the route for viewing monthly archives
            
    $route = new Zend_Controller_Router_Route('user/:username/archive/:year/:month/*',
                                                      array(
    'controller' => 'user',
                                                              
    'action' => 'archive'));

            
    $controller->getRouter()->addRoute('archive'$route);

            
    // setup the route for user tag space
            
    $route = new Zend_Controller_Router_Route('user/:username/tag/:tag/*',
                                                      array(
    'controller' => 'user',
                                                              
    'action' => 'tag'));

            
    $controller->getRouter()->addRoute('tagspace'$route);
            
            
    // setup the route for section home pages
            
    $route = new Zend_Controller_Router_Route('content/:section/:action/*',
                                                      array(
    'controller' => 'content',
                                                            
    'action' => 'index'));
                                                      
            
    $controller->getRouter()->addRoute('section'$route);
            
            
    // setup the route for viewing an article
            
    $route = new Zend_Controller_Router_Route('content/:section/view/:url/*',
                                                      array(
    'controller' => 'content',
                                                            
    'action' => 'view'));

            
    $controller->getRouter()->addRoute('article'$route);
            
            
    // start the controller
            
    $controller->dispatch();
        }
        catch (
    Exception $ex) {
            
    $logger->emerg($ex->getMessage());

            
    header('Location: /error.html');
            exit;
        }
    ?>
    The following code sections are the functions that run the relevant parts of the content system I'm having issues with -

    DatabaseObject_ContentArticle-
    PHP Code:
        class DatabaseObject_ContentArticle extends DatabaseObject
        
    {
            public 
    $profile null;

            const 
    STATUS_DRAFT 'D';
            const 
    STATUS_LIVE 'L';
            const 
    FRONT_PAGE_YES 'Y';
            const 
    FRONT_PAGE_NO 'N';

            public function 
    __construct($db)
            {
                
    parent::__construct($db'content_articles''article_id');

                
    $this->add('section_name');
                
    $this->add('user_id');
                
    $this->add('url');
                
    $this->add('ts_created'time(), self::TYPE_TIMESTAMP);
                
    $this->add('status'self::STATUS_DRAFT);
                
    $this->add('front_page'self::FRONT_PAGE_NO);

                
    $this->profile = new Profile_ContentArticle($db);
            }

    --------- 
    More functions before here ----------

            public function 
    loadLiveArticle($url)
            {
                
    $url trim($url);
                
                if (
    strlen($url) == 0)
                    return 
    false;
                    
                
    $select $this->_db->select();
                
                
    $select->from($this->_table$this->getSelectFields())
                       ->
    where('url = ?'$url)
                       ->
    where('status = ?'self::STATUS_LIVE);
                       
                return 
    $this->_load($select);
            } 
    ContentController.php -

    PHP Code:
    <?php
        
    class ContentController extends CustomControllerAction
        
    {
            protected 
    $section null;

            public function 
    preDispatch()
            {
                
    // call parent method to perform standard predispatch tasks
                
    parent::preDispatch();

                
    // retrieve the request object so we can access requested section and action
                
    $request $this->getRequest();

                
    // check if already dispatching the section not found action. If we are
                // then we don't want to execute the remainder of this method
                
    if (strtolower($request->getActionName()) == 'sectionnotfound')
                    return;

                
    // retrieve section name from request and clean the string
                
    $sectionname trim($request->getUserParam('section'));

                
    // if no section is provided, redirect to the site home page
                
    if (strlen($sectionname) == 0)
                    
    $this->_redirect($this->getUrl('index''index'));

                
    // load the articles, based on section in request. If the section record
                // is not loaded then forward to notFoundAction so a 'section not found'2
                // message can be shown to the user.

                
    $this->section = new DatabaseObject_ContentArticle($this->db);

                if (!
    $this->section->loadBySection($sectionname)) {
                    
    $this->_forward('sectionNotFound');
                    return;
                }

                
    // add a link to the breadcrumbs so all actions in this controller
                // link back to the section home page
                
    $this->breadcrumbs->addStep(
                    
    $this->section->section_name,
                    
    $this->getCustomUrl(
                        array(
    'sectionname' => $this->section->sectionname,
                              
    'action' => 'index'),
                        
    'section'
                    
    )
                );

                
    // make the section data available to all templates in this controller
                
    $this->view->section $this->section;
            }
            
            public function 
    indexAction()
            {
                
    // get the section name from the URL to pass to SQL to get the articles
                // for only that section
                
    $request $this->getRequest();
                
    $sectionname trim($request->getUserParam('section'));
                
                
    // limit the amount of returned results
                
    $limit 10;
                
                
    $options = array(
                    
    'status' => DatabaseObject_ContentArticle::STATUS_LIVE,
                    
    'limit' => $limit,
                    
    'order' => 'p.ts_created desc',
                    
    'section_name' => $sectionname
                
    );
                
                
    $articles DatabaseObject_ContentArticle::GetArticles($this->db,
                                                                       
    $options);
                                                                       
                
    $this->view->articles $articles;
            }
            
            public function 
    viewAction()
            {
                
    $request $this->getRequest();
                
    $url trim($request->getUserParam('url'));
                
                
    // if no URL specified, return to the section home page
                
    if (strlen($url) == 0) {
                    
    $this->_redirect($this->getCustomUrl(
                        array(
    'section' => $this->section->section_name,
                              
    'action' => 'index'),
                        
    'section'
                    
    ));
                }
                
                
    // try to load the article
                
    $article = new DatabaseObject_ContentArticle($this->db);
                
    $article->loadLiveArticle($url);
                
                
    // if the post wasn't loaded redirect to article not found
                
    if (!$article->isSaved()) {
                    
    $this->_forward('articleNotFound');
                    return;
                }
                
                
    // build the breadcrumbs
                
    $this->breadcrumbs->addStep($article->profile->title);
                
                
    // make the article available to the templates
                
    $this->view->article $article;
            }
            
            public function 
    articleNotFoundAction()
            {
                
    $this->breadcrumbs->addStep('Article Not Found');
            }
        }
    ?>
    I'm using the following URL to try to access the article, this is a local testing server URL so isn't live online -

    http://dcmsv15/content/music/view/testing-2

    My htaccess file contains this, just incase it is helpful -

    Code:
    SetEnv APP_CONFIG_FILE "settings.ini"
    SetEnv APP_CONFIG_SECTION "development"
    php_value include_path .:/Users/boardy/Documents/Devarios/D-CMSv1-5/include:/Users/boardy/Documents/Devarios/D-CMSv1-5/pear/PEAR
    php_value magic_quotes_goc 0
    php_value register_globals 0
    
    RewriteEngine on
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    If anything else is needed please let me know.

    I've been trying to figure out what's wrong over the last few days and have tried a few different things.

    Can anyone help please, I'm still pretty new to the ZF?

    Cheers
    Adam
    Adam
    Devarios
    boardy@live.com

  2. #2
    SitePoint Enthusiast boardy's Avatar
    Join Date
    Feb 2007
    Location
    Lincoln, UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone help with this?

    I'm really stuck and really need to try get this finished.

    Adam
    Adam
    Devarios
    boardy@live.com

  3. #3
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might also try posting it here: http://www.zfforums.com

    They can be slow to answer, but since it's focused on the Zend Framework specifically I've found I usually get better responses there.

  4. #4
    SitePoint Enthusiast boardy's Avatar
    Join Date
    Feb 2007
    Location
    Lincoln, UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've posted this on ZFF also, does no one have any idea what's not working here?

    Adam
    Adam
    Devarios
    boardy@live.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •