When you are working with CakePHP framework and you try to retrieve the variables which have been sent through GET or POST.
For POST variables you have
For $_POST['key'] we have
$this->request->data('key');
For GET variables you have
For $_GET['kpa'] we have
$this->request->query('kpa');
Sep 18, 2015
Sep 8, 2015
HTML5 vs HTML
There
is some differences between HTML and HTML5. So though, we have:
HTML5
was designed to replace both HTML 4, XHTML, and the HTML DOM Level 2.
And
XHTML is HTML + XML. For a better syntax and for a better
administration they had to force HTML to be proper: for instance, if
you open this tag <p> you have to close the tag with
</p>.
The
main goals of HTML5 are:
-
Deliver rich content as graphics or movies without the need of
additional plugins as Flash, for instance;
-
Provide better semantic support for web page structure. For this,
HTML5 introduces new structural element tags;
-
Provide better cross-platform support (for PC browser, tablet or
smartphone);
-
Provide a stricter parsing standard to simplify error handling,
ensure more consistent cross-browser behavior.
HTML5
has improved the support for
embedding graphics, video and audio. For that HTML5 has
some new tags: <canvas>, <audio>,
<video>
HTML5
has introduced web workers.
A web worker is a script that runs in the background, in another
thread, without the page has to wait for it to complete. The visitor
can continue to interact with the page while the web worker runs in
the background.
HTML5
has new semantic tags to
complement the structural logic of modern web applications. Here we
have:
<main>
<nav>
<article>
<section>
<header>
<footer>
<aside>
HTML5
has new controls like
<calendar>
<date>
<time>
<email>
<url>
<search>
HTML5
has new extensions to the Javascript API as geolocation,
drag-and-drop, storage
and caching.
Aug 28, 2015
CakePHP and PHP version
I was trying to code at my project. It was OK on my localhost webserver. But... when I moved the files on the real webserver I had a problem.
I didn't know what could that be. I got errors just on some pages. Not at all pages of my website.
Then, I realized that, perhaps, my version of PHP could be too old. Actually, not my version but real webserver version.
Indeed, the problem it was with PHP version which is 5.3 and this version doesn't know about the arrays declared like this:
$ar = ['key1' => 'value1', 'key2' => 'value2'];
It knows only like this:
$ar = array('key1' => 'value1', 'key2' => 'value2');
I got this issue when I tried to make a Form and I finished to have this PHP code
echo $this->Form->input('name', [
'label'=>[
'class' => 'ContactInput',
'text' => 'Name:' . $messgError['name']
]
]);
I didn't know what could that be. I got errors just on some pages. Not at all pages of my website.
Then, I realized that, perhaps, my version of PHP could be too old. Actually, not my version but real webserver version.
Indeed, the problem it was with PHP version which is 5.3 and this version doesn't know about the arrays declared like this:
$ar = ['key1' => 'value1', 'key2' => 'value2'];
It knows only like this:
$ar = array('key1' => 'value1', 'key2' => 'value2');
I got this issue when I tried to make a Form and I finished to have this PHP code
echo $this->Form->input('name', [
'label'=>[
'class' => 'ContactInput',
'text' => 'Name:' . $messgError['name']
]
]);
Aug 26, 2015
CakePHP 2 - Forms
When you try to create a new form in CakePHP framework using FormHelper, you may have this error:
echo $this->Form->create(false, array('url' => '/contact'));
Good luck!
Missing Database TableAnd if you read very carefully the Book of CakePHP will see something like that:
You can also pass false for $model. This will place your form data into the array: $this->request->data (instead of in the sub-array: $this->request->data['Model']). This can be handy for short forms that may not represent anything in your database.So, in your view file like APP/View/Contact/index.ctp, you have to start with this line:
echo $this->Form->create(false, array('url' => '/contact'));
Good luck!
Aug 19, 2015
CakePHP 2.* how to use custom complex sql Query with model
Let's suppose that we have MySQL database with table categories:
CREATE TABLE `categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(64) DEFAULT NULL,
`description` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
Then, in CakePHP framework, you want to call a simple query as you did it with mysql_query in PHP with no framework.
For that you have the class Model::query()
First, you build the model. You don't want to use predefined Models for a table (like the model Categories for DB table Categories). Because you want to use perhaps this query for extracting data from two tables which are related.
So, first you have to create the model. For this you have to create the file APP/Model/Categs.php
class Categ extends AppModel {
public $useTable = false; // it is mandatory to have this line. Whithout this line,
// the Controller will search for table Categ; it doesn't matter that you have a sql query
public function getDataFromMyTable(){
$d = $this->query("SELECT * FROM categories");
return $d;
}
}
Second, you have to create the Controller. The file will be: APP/Controller/CategsController.php
class CostsController extends AppController {
public function index(){
$this->loadModel('Categ');
$rezQuery = $this->Categ->getDataFromMyTable();
$this->set('cs', $rezQuery);
}
}
?>
And now we have to create the view. We create folder APP/View/Categs (if this folder doesn't exists). And then we create the file index.ctp into this folder. The name of the ctp file should be the same as name of the function from Controller. In index.ctp we write:
CREATE TABLE `categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(64) DEFAULT NULL,
`description` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
Then, in CakePHP framework, you want to call a simple query as you did it with mysql_query in PHP with no framework.
For that you have the class Model::query()
First, you build the model. You don't want to use predefined Models for a table (like the model Categories for DB table Categories). Because you want to use perhaps this query for extracting data from two tables which are related.
So, first you have to create the model. For this you have to create the file APP/Model/Categs.php
class Categ extends AppModel {
public $useTable = false; // it is mandatory to have this line. Whithout this line,
// the Controller will search for table Categ; it doesn't matter that you have a sql query
public function getDataFromMyTable(){
$d = $this->query("SELECT * FROM categories");
return $d;
}
}
Second, you have to create the Controller. The file will be: APP/Controller/CategsController.php
class CostsController extends AppController {
public function index(){
$this->loadModel('Categ');
$rezQuery = $this->Categ->getDataFromMyTable();
$this->set('cs', $rezQuery);
}
}
?>
And now we have to create the view. We create folder APP/View/Categs (if this folder doesn't exists). And then we create the file index.ctp into this folder. The name of the ctp file should be the same as name of the function from Controller. In index.ctp we write:
Subscribe to:
Posts (Atom)