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!

  • Digg
  • del.icio.us
  • blogmarks
  • Reddit
  • Simpy
  • StumbleUpon
  • Technorati
  • description
  • Ma.gnolia
  • Slashdot
  • Sphinn
  • Spurl

Related Posts

cash advance online
New Audi Parts Solf @ Trade Prices

Tags: , ,

Posts linking to this article:

[Web] 連結分享
最近要減少網摘的文章以及連結的說明了,因為那花去我太多時間(看底下那堆連結...Orz) 。 接下來要把重心放在新的專案上,以及更深入瞭解Zend Framework 及物件導向的相關知識。 註:這次還偷懶,直接從Firefox 匯出來貼...如果有發現歸錯類的話,還望 ...

re-found the current rails tutorial, plus some news from Cork ...
Quanta accidentally begun to consume almost 100% of computing power. Which gives me some time to collect the bits and pieces I twittered about so far today. First of all, the Cork, Ireland, conference I mentioned yesterday, ...

CMS mit dem Zend Framework
Henrik Sarvell startete vor einiger Zeit damit, ein Content Management System auf Basis des Zend Frameworks zu entwickeln. Dies hat er auch enorm vorangetrieben und einige Teile davon veröffentlicht. Gestern hat er den (vorerst) letzten ...

Subscribe with Google Reader

Viewing 3 Comments

Trackbacks

close Reblog this comment
blog comments powered by Disqus