On plain cakePHP 1.2.3.8166 installation with only one dummy "pizza"
plugin,
View class seeks view and element files on strange places.
Output of $path variable in View::_paths()
Array
(
[0] => C:\AppServ\cake\app\views\plugins\pizza\
[1] => C:\AppServ\cake\cake\libs\view\plugins\pizza\
[2] => C:\AppServ\cake\app\plugins\pizza\views\
[3] => C:\AppServ\cake\app\views\
[4] => C:\AppServ\cake\cake\libs\view\
)
I can se many "file_exists()" in View class when profiling cake with
xdebug,
and I think this could be improved much.
Cake will seek foreach above path when rendering view or element.
Snippet form View::element() method:
foreach ($paths as $path) {
if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
$file = $path . 'elements' . DS . $name . $this->ext;
break;
} elseif (file_exists($path . 'elements' . DS . $name . '.thtml'))
{
$file = $path . 'elements' . DS . $name . '.thtml';
break;
}
}
Snippet form View::_getViewFileName() method:
foreach ($paths as $path) {
if (file_exists($path . $name . $this->ext)) {
return $path . $name . $this->ext;
} elseif (file_exists($path . $name . '.ctp')) {
return $path . $name . '.ctp';
} elseif (file_exists($path . $name . '.thtml')) {
return $path . $name . '.thtml';
}
}
Snippet form View::_getLayoutFileName() method:
$exts = array($this->ext, '.ctp', '.thtml');
foreach ($paths as $path) {
foreach ($exts as $ext) {
if (file_exists($path . $file . $ext)) {
return $path . $file . $ext;
}
}
}
My conclusion:
1. As you can see from snippets above, there will be many failed
file_exists() calls.
2. Something is wrong with path order from which cake seeks files (see
Output of $path from above). First two paths are strange.Is it a bug?
3. "thtml" extension should be deprecated for performance improvement
(I/O)
Consider following scenario:
Pizza plugin has it's own layout and "index" view with 3 elements:
Cake will find:
- "index" view on 7th attempt!
- layout on 5th attempt
- first element on 5th attempt
- second element on 5th attempt
- third element on 5th attempt
----------------------------------------
SUM= 22 failed file_exist, only for one view render
If you setup additional view paths in Configure (bootstap $viewPaths
array), things got even worse.(Many CMS apps do that)
This file seeking takes most of View render process time (xdebug)
I'm not sure if this calculations are correct, please correct me.
Other files (controller, models, helpers) are cached (paths) once
found by App::import,
so I thnik that view rendering logic is far from optimal.
PS:
Option to extend requestAction or at least have some callback
beforeRequestAction() would be very nice.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---