About the Tutorial



Download 1,5 Mb.
Pdf ko'rish
bet43/96
Sana29.01.2022
Hajmi1,5 Mb.
#416930
1   ...   39   40   41   42   43   44   45   46   ...   96
Bog'liq
Download CakePHP Tutorial (PDF Version)

the name of the variable
and 
its value

Example 
Make Changes in the 
config/routes.php
file as shown in the following program. 
config/routes.php 
use Cake\Core\Plugin; 
use Cake\Routing\RouteBuilder; 
use Cake\Routing\Router; 
Router::defaultRouteClass('DashedRoute'); 
Router::scope('/', function (RouteBuilder $routes) { 
10.
 
CakePHP — Views 


CakePHP 
26 
$routes->connect('template',['controller'=>'Products','action'=>'view']); 
$routes->fallbacks('DashedRoute'); 
}); 
Plugin::routes(); 
Create a 
ProductsController.php
file at 
src/Controller/ProductsController.php

Copy the following code in the controller file. 
src/Controller/ProductsController.php 
namespace App\Controller; 
use App\Controller\AppController; 
class ProductsController extends AppController{ 
public function view(){ 
$this->set('Product_Name','XYZ'); 


?> 
Create a directory Products at 
src/Template
and under that folder create a 
View
file 
called 
view.ctp
. Copy the following code in that file. 
src/Template/Products/view.ctp 
Value of variable is:  
Execute the above example by visiting the following URL. 
http://localhost:85/CakePHP/template


CakePHP 
27 
Output 
The above URL will produce the following output. 


CakePHP 
28 
Many times, while making web pages, we want to repeat certain part of pages in other 
pages. CakePHP has such facility by which one can extend view in another view and for 
this, we need not repeat the code again. The 
extend()
method is used to extend views in 
View
file. This method takes one argument, i.e., the name of the view file with path. Don’t 
use extension .ctp while providing the name of the View file. 
Example 
Make changes in the 
config/routes.php
file as shown in the following program. 
config/routes.php 
use Cake\Core\Plugin; 
use Cake\Routing\RouteBuilder; 
use Cake\Routing\Router; 
Router::defaultRouteClass('DashedRoute'); 
Router::scope('/', function (RouteBuilder $routes) { 
$routes->connect('extend',['controller'=>'Extends','action'=>'index']); 
$routes->fallbacks('DashedRoute'); 
}); 
Plugin::routes(); 
Create a 
ExtendsController.php
file at 
src/Controller/ExtendsController.php
. Copy 
the following code in the controller file. 
src/Controller/ExtendsController.php 
namespace App\Controller; 
use App\Controller\AppController; 
class ExtendsController extends AppController{ 
11.
 
CakePHP — Extending Views 


CakePHP 
29 
public function index(){ 


?> 
Create a directory 
Extends
at 
src/Template
and under that folder create a 
View
file 
called 
header.ctp
. Copy the following code in that file. 
src/Template/Extends/header.ctp 
 

Download 1,5 Mb.

Do'stlaringiz bilan baham:
1   ...   39   40   41   42   43   44   45   46   ...   96




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish