Bonjour,
J'ai suivi ce tuto :
Tutoriel vidéo PHP : Développer un site de A a Z
moi je que je veux de faire une jointure entre la table post et la table catégorié mais dans toute la formation il n y'a aucune jointure c'est quelqu'un peut maider a resoudre ce probleme
PostsController
class PostsController extends Controller{
function view($id,$slug){
$this->loadModel('Post');
$condition = array('id' => $id, 'type_post' => 'post', 'online' => 1);
$d['post']=$this->Post->findFirst(array(
'fields' => 'id,content,slug,name_post',
'conditions'=> $condition
));
if(empty($d['post'])){
$this->e404('Page introuvable');
}
if($slug != $d['post']->slug) {
$this->redirect("posts/view/id:$id/slug:".$d['post']->slug,301);
}
$this->set($d);
}
Model
public function find($req){
$sql = 'SELECT ';
if(isset($req['fields'])){
if(is_array($req['fields'])){
$sql .= implode(', ', $req['fields']);
}else{
$sql .= $req['fields'];
}
}else{
$sql .= '*';
}
$sql .= ' FROM '.$this->table.' as '.get_class($this).' ';
if(isset($req['conditions'])){
$sql .= 'WHERE ';
if(!is_array($req['conditions'])){
$sql .= $req['conditions'];
}else{
$cond = array();
foreach ($req['conditions'] as $k => $v) {
if(!is_numeric($v)){
$v=''.$this->db->quote($v).'';
//$v="$v";
}
$cond[] = "$k=$v";
}
$sql .= implode(' AND ', $cond);
}
}
if(isset($req['limit'])){
$sql .= ' LIMIT ' .$req['limit'];
}
$pre = $this->db->prepare($sql);
$pre->execute();
return $pre->fetchAll(PDO::FETCH_OBJ);
}
public function findFirst($req){
return current($this->find($req));
}