Guide Informatique PDF
Guide Informatique PDF
Guide Informatique PDF
The local development server can be customized with three command line
options:
You can use the --host CLI option to specify a different host to run the
application at:
By default, the server runs on port 8080 but you might have more than
one site running, or already have another application using that port.
You can use the --port CLI option to specify a different one:
You can also specify a specific version of PHP to use, with the --php
CLI option, with its value set to the path of the PHP executable you
want to use:
$query = $db->table('table_name')->get();
$data = [
'title' => $title,
'name' => $name,
'date' => $date
];
$builder = $this->db->table('companies_to_company');
return $builder->selectCount($column, 'total')
->where($column, $company_id)
->get()
->getRowArray();
$builder->db->table('blog');
$builder->select('*');
$builder->join('comments', 'comments.id = blogs.id');
$query = $builder->get();
$builder = $this->db->table('companies');
return $builder->select($columns)
->getWhere(['id' => $company_id])
->getRowArray();
return redirect()->route('forgot_password');
Notice that there are no braces. Instead, the end brace is replaced with
endforeach.
Each of the control structures listed above has a similar closing
syntax: endif, endfor, endforeach, and endwhile
Also notice that instead of using a semicolon after each structure (except the
last one),
there is a colon. This is important!
Here is another example, using if/elseif/else. Notice the colons:
<h3>Hi Sally</h3>
<h3>Hi Joe</h3>
SESSION CI4 :
$session = \Config\Services::session();
$session->set($array);
Ex : $this->session->set($sessionData);
$newdata = [
'username' => 'johndoe',
'email' => 'johndoe@some-site.com',
'logged_in' => TRUE
];
$this->session->set($newdata);
$this->session->setFlashdata('item', 'value');
$this->session->getFlashdata('item');
Note :
// Go to specific UI
return redirect()->to('/admin');
// Go to a named/reverse-routed URI
return redirect()->route('named_route');
// Keep the old input values upon redirect so they can be used by the `old()` return
redirect()->back()->withInput();
// Use it in a view
<a href="<?= route_to('login') ?>">Login</a>
setRule() :
This method sets a single rule. It takes the name of field as the first
parameter, an optional label and a string with a pipe-delimited list of rules
that should be applied:
The field name must match the key of any data array that is sent in. If the
data is taken directly from $_POST, then it must be an exact match for the
form input name
$validation->setRules([
'username' => 'required',
'password' => 'required|min_length[10]'
]);
Views Your views look much like before, but they are invoked differently ...
instead of CI3’s $this->load->view(x); you can use echo view(x); CI4
supports view “cells”, to build your response in pieces The template parser is
still there, but substantially enhanced
Alternative Echos
Normally to echo, or print out a variable you would do this:
<ul>
<?php foreach ($todo as $item) : ?>
<li> <?= $item ?> </li>
<?php endforeach ?>
</ul>
$this->validation = \Config\Services::validation();
$this->session = \Config\Services::session();
if ($bottom_content && !$content_only):
if (is_array($bottom_content)):
foreach ($bottom_content as $v) :
echo view($v);
endforeach;
else:
echo view($bottom_content);
endif;
endif;
helper(['form', 'url']);
<?php
namespace App\Models;
use CodeIgniter\Model;
class CountryModel extends Model {
return $options;
}
}
<?php if (file_exists(ROOTPATH . ASSETS . 'img/favicon.ico')): ?>
<link rel="icon" href="<?= ASSETS . 'img/favicon.ico' ?>" />
<?php endif; ?>
<?php if (isset($css_min) && !empty($css_min)): ?>
<?php echo trim($css_min) . "\n"; ?>
<?php else: ?>
<?php foreach ($css as $url): ?>
<link rel="stylesheet" type="text/css" href="<?php echo $url;
?>" />
<?php endforeach; ?>
<?php endif; ?>