Hello, > > I want to have new controllers appear in menu
I wrote this code some month ago. (based on the "cakeinfo") cakeinfo() http://www.1x1.jp/blog/2007/01/cakephp_cakeinfo.html shun /** * make file list * * @param array $dirPaths * @return array */ function _getFileListDirs($dirPaths) { $array = array(); foreach ($dirPaths as $dirPath) { $array += _getFileList($dirPath); } return $array; } /** * make file list * * @param string $dirPath * @return array */ function _getFileList($dirPath) { $array = array(); if (!file_exists($dirPath) || !is_dir($dirPath)) { return $array; } $d = dir($dirPath); while ($file = $d->read()) { if ($file == '.' || $file == '..') { continue; } if (substr($dirPath, -1) != DS) { $dirPath .= DS; } $path = $dirPath . $file; if (is_dir($path)) { $array += _getFileList($path); } $array[] = $path; } return $array; } /** * get view list * * @param string $ctrlName * @return array */ function _getViewList($ctrlName,$conf) { $array = array(); foreach ($conf->viewPaths as $dirPath) { $dirPath .= Inflector::underscore($ctrlName); $array[] = sprintf('[%s]', $dirPath); $offset = strlen($dirPath) + 1; // add DS character $paths = _getFileList($dirPath); foreach ($paths as $path) { if (is_file($path) && preg_match("/(.ctp|.thtml)$/", $path)) { $array[] = substr($path, $offset); } } } return $array; } echo "<h2>Existing Controllers & Views</h2>"; if(defined("CAKE_ADMIN")){ $admin_route = CAKE_ADMIN; } $conf = Configure::getInstance(); $paths = _getFileListDirs($conf->controllerPaths); foreach ($paths as $path) { if (is_file($path) && preg_match("/^(.+)_controller\.php$/", basename($path), $m)) { $ctrlName = Inflector::camelize($m[1]); loadController($ctrlName); $class = $ctrlName . 'Controller'; $obj = new $class(); $v['view'] = _getViewList($ctrlName,$conf); $methods = get_class_methods($obj); $original = get_class_methods("Controller"); $diff_methods = array_diff($methods,$original); echo $class."<BR> ("; while(list($key, $val) = each($diff_methods)){ echo " ".$val; } echo ")<BR>"; $BASE = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; echo "VIEWS ("; for($i=1;$i<count($v['view'])-1;$i++){ $one_template = $v['view'][$i]; $one_template = str_replace(".thtml", "", $one_template); $one_template = str_replace(".ctp", "", $one_template); $one_controller = str_replace("Controller","",$class); if(strlen($admin_route) && strpos($one_template,CAKE_ADMIN) !== FALSE){ $one_template_url = str_replace(CAKE_ADMIN."_","",$one_template); $one_controller = CAKE_ADMIN."/".$one_controller; } else { $one_template_url = $one_template; } echo ($i==1?"":", "). "<a href='". $BASE.Inflector::underscore($one_controller)."/".$one_template_url."/ 1'>". $one_template . "</a>"; } echo ")<BR><BR>"; } } On 6月7日, 午後8:58, Joshua Benner <[EMAIL PROTECTED]> wrote: > I supposed you could base it off of the contents of the controllers folder. > > > > igor'OK wrote: > > I have situation when i need to have a list of all controllers, to > > generate menu to access all of them > > Currently i keep custom array with the list of already created > > controllers, but this way is not acceptable > > I want to have new controllers appear in menu > > Can anybody help me with it?- 引用テキストを表示しない - > > - 引用テキストを表示 - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---