Skip to content

Commit fc01d74

Browse files
eddieajauAndrew Eddie
authored andcommitted
Allows JViewHtml->getPath to set the extension of the layout file.
Allows for a different extension to be set for the layout file. Adding a default extension to getPath easily allows the developer to derive their own views with a new default.
1 parent 5e91b55 commit fc01d74

File tree

1 file changed

+35
-0
lines changed
  • manual/en-US/chapters/packages

1 file changed

+35
-0
lines changed

manual/en-US/chapters/packages/mvc.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,38 @@ catch (RuntimeException $e)
354354
// Handle database error.
355355
}
356356
```
357+
358+
The default extension for layouts is ".php". This can be modified in derived views by changing the default value for the extension argument. For example:
359+
360+
```php
361+
/**
362+
* My custom HTML view.
363+
*
364+
* @package Examples
365+
* @since 12.1
366+
*/
367+
class MyHtmlView extends JViewHtml
368+
{
369+
/**
370+
* Override the parent method to use the '.phtml' extension for layout files.
371+
*
372+
* @param string $layout The base name of the layout file (excluding extension).
373+
* @param string $ext The extension of the layout file (default: "phtml").
374+
*
375+
* @return mixed The layout file name if found, false otherwise.
376+
*
377+
* @see JViewHtml::getPath
378+
* @since 12.1
379+
*/
380+
public function getPath($layout, $ext = 'phtml')
381+
{
382+
return parent::getPath($layout, $ext);
383+
}
384+
}
385+
```
386+
387+
##### Revision history
388+
389+
The new View package was added in 12.1.
390+
391+
The extension argument was added to `JViewHtml->getPath` in 12.3.

0 commit comments

Comments
 (0)