Writing a CMS/Community with Smarty and the Zend Framework: Part 10


As some of you know, I’ve got other things to do at the moment. The cms/community project is iced. Therefore I’ve created a Google project out of it.

ZF CMS/Community source

The source for the Flex/Flash uploader is here.

Some changes since the last part:

class ControllerPlugin extends Zend_Controller_Plugin_Abstract{
    public function preDispatch( Zend_Controller_Request_Abstract $request ){
    	$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
      $controllerName = $request->getControllerName();
      $moduleName	= $request->getModuleName();
      if (empty($controllerName))
        $controllerName = $dispatcher->getDefaultController();
			
      $className = $dispatcher->formatControllerName($controllerName);
        
		if($className){
      try{
				$controllerDirectories = $dispatcher->getControllerDirectory();
				if($moduleName == 'default'){
          Zend_Loader::loadClass($className, $controllerDirectories['default']);
				}else{
					$dir = $controllerDirectories[ strtolower($moduleName) ]."/".$className.".php";
					include_once($dir);
					$className = ucfirst($moduleName)."_".$className;
				}
        $actionName = $request->getActionName();

        if (empty($actionName))
            $actionName = $dispatcher->getDefaultAction();
        $methodName = $dispatcher->formatActionName($actionName);

        $class = new ReflectionClass( $className );

        if( $class->hasMethod( $methodName ) )
            return;
        }catch (Zend_Exception $e){
        }
     }
    // we only arrive here if can't find controller or action
    $request->setControllerName( 'index' );
    $request->setActionName( 'noroute' );
    $request->setDispatched( false );
    }
}

The moste notable thing here is the if($moduleName… part. If the module name is not default then we basically tell ZF to take a hike and do it freestyle instead. This change was required in order to get the folder structure I want to work. With having the admin in it’s own self contained folder.

That means loadModel in ExtController could be made much simpler since we – with the above code – is moving the whole module logic upwards in the logical chain:

function loadModel($table){
  $class_name = strtolower($table);
  $file_name = $class_name.".php";
  include_once($file_name);
  return new $class_name;
}

If I had to do this thing all over again I might just have scrapped the whole routing logic and written my own much simpler version of the routing that would’ve been much more flexible. I feel that there has been too much fighting against the framework conventions in this area.

INSTALL:
– There should be an SQL file in there that you can import to get some test data going.
– Make sure mod_rewrite is turned on and working properly.
– Check what you have to do in the framework_config/config.ini file, I think you will get the picture.
– Make sure you link to ZF and Smarty properly, default is ../PEAR/Zend and ../PEAR/libs for Smarty.

TODO:
– Getting rid of repeat select statements for optimization.
– What happens if the user doesn’t have flash enabled when we have a shockwave size set to 0? Most likely the automatic download procedure will be broken so this needs fixing somehow. Perhaps with that new PHP module that will allow multiple uploads with progress feedback? If that module is working properly we can scrap the whole Shockwave uploader which would be great.
– Get the City/Country/Whatever drop downs out of the code and into their own tables, editable from the admin section of course.
– The whole admin interface where it should be possible to edit articles, users and menus to name a few things. At the moment the only thing that works is editing global config values.

If you are interested in maintaining and working on this thing comment here or email me or whatever and I’ll give you the Google code password so you can start using subversion.

Good luck!

Related Posts

Tags: , ,