Are there differences between view blocks or elements in cakephp?

make any difference using blocks or view elements for a simple navigation bar or dynamic menu with mysql content (using the method requestAction())? Which is more suitable?

+4
source share
1 answer

Yes, there is a difference. Elements are just php / HTML snippets that you write in a separate .ctp file that will be inserted where you call $this->element().

Blocks are harder to explain. Blocks are areas that you can define elsewhere. Blocks may contain elements. The best example for explaining the blocks that I can think of is in the standard CakePHP layout, there are lines in the header

echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');

, , "meta", "css" "script". , css, script $this->fetch(); . , :

echo $this->Html->script('javascript', array('block' => 'script')); 

javascript script, , , . , , javascript, view.ctp.

, script, css - , . , , :

$this->start('block');
//Block contents here
$this->end();

?

. , , , , , .

, , , , , .

. , . $name . , , . , $name , . , , view.ctp. MVC.

​​ : http://book.cakephp.org/2.0/en/views.html

+9

Source: https://habr.com/ru/post/1544520/


All Articles