MVC :Comment rediriger une vue vers un contrôleur qui ira dans une autre vue ?
-
29-10-2019 - |
Question
Je suis le modèle MVC dans PHP + JS + HTML + CSS Aussi, j'utilise Codeigniter comme framework.
Je veux savoir que dois-je faire pour rediriger vers un autre contrôleur.Je suis dans la page d'accueil de mon projet.et quand je clique sur "détails" (div = prod_details) pour un produit, quelle est censée être la référence.
Pour obtenir de l'aide, voici mon code
MA MAISON contrôleur
class ordiDepot extends Controller {
function ordiDepot(){
parent::Controller();
}
function index(){
$data['base'] = $this->config->item('base_url');
$data['css'] = $this->config->item('chemin').'views/style.css';
$data['image'] = $this->config->item('chemin').'views/images';
$data['js'] = $this->config->item('chemin').'views/boxOver.js';
$data['abs'] = 'ordiDepot/accueil';
$this->load->view('ordiDepotH',$data);
$this->load->view('ordiDepotB',$data);
$this->load->view('ordiDepotF',$data);
}
function accueil($page){
$data['details_page'] = $this->config->item($page);
$data['css'] = $this->config->item('chemin').'views/style.css';
$this->load->view('details.php',$data);
}
}
Mon avis
<div class="left_content">
<div class="title_box">Pieces</div>
<ul class="left_menu">
<li class="odd"><a href="services.html">Processeurs</a></li>
<li class="even"><a href="services.html">Carte Mere</a></li>
<li class="odd"><a href="services.html">Carte Video</a></li>
<li class="even"><a href="services.html">Carte Reseau</a></li>
<li class="odd"><a href="services.html">Bloc d'alimentation</a></li>
<li class="even"><a href="services.html">Disque dur</a></li>
<li class="odd"><a href="services.html">Boitiers</a></li>
</ul>
<div class="title_box">Produit en special</div>
<div class="border_box">
<div class="product_title"><a href="details.html">Motorola 156 MX-VL</a></div>
<div class="product_img"><a href="details.html"><img src= <?php echo $image?>/laptop.png alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
MERCI À TOUS
<div class="banner_adds">
<a href="#"><img src="images/bann2.jpg" alt="" title="" border="0" /></a>
</div>
Nouveaux produits
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Motorola 156 MX-VL</a></div>
<div class="product_img"><a href="details.html"><img src=<?php echo $image?>/laptop.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Add to cart] body=[ ] fade=[on]"><img src="<?php echo $image;?>/cart.gif" alt="" title="" border="0" class="left_bt" /></a>
<a href="details.php" class="prod_details">details</a>
</div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Ipod</a></div>
<div class="product_img"><a href="details.html"><img src= <?php echo $image?>/p4.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier] body=[ ] fade=[on]"><img src="<?php echo $image;?>/cart.gif" alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Webcam Samsung</a></div>
<div class="product_img"><a href="details.html"><img src=<?php echo $image?>/p5.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier] body=[ ] fade=[on]"><img src="<?php echo $image;?>/cart.gif" alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="<?php echo $abs;?>/details">Motorola 156 MX-VL</a></div>
<div class="product_img"><a href="details.html"><img src=<?php echo $image?>/laptop.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier] body=[ ] fade=[on]"><img src="<?php echo $image;?>/cart.gif" alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Iphone</a></div>
<div class="product_img"><a href="details.html"><img src=<?php echo $image?>/p4.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier] body=[ ] fade=[on]"><img src=<?php echo $image;?>/cart.gif alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Webcam Samsung</a></div>
<div class="product_img"><a href="details.html"><img src=<?php echo $image?>/p5.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier] body=[ ] fade=[on]"><img src= <?php echo $image;?>/cart.gif alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
Accessoires <div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Motorola 156 MX-VL</a></div>
<div class="product_img"><a href="details.html"><img src= <?php echo $image?>/laptop.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier] body=[ ] fade=[on]"><img src="<?php echo $image;?>/cart.gif" alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Iphone</a></div>
<div class="product_img"><a href="details.html"><img src=<?php echo $image?>/p4.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier] body=[ ] fade=[on]"><img src="<?php echo $image;?>/cart.gif" alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="details.html">Webcam Samsung</a></div>
<div class="product_img"><a href="details.html"><img src= <?php echo $image?>/p5.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<a href="#" title="header=[Ajouter panier body=[ ] fade=[on]"><img src= <?php echo $image;?>/cart.gif alt="" title="" border="0" class="left_bt" /></a>
<a href="details.html" class="prod_details">details</a>
</div>
</div>
Panier
<div class="cart_details">
3 items <br />
<span class="border_cart"></span>
Total: <span class="price">350$</span>
</div>
<div class="cart_icon"><a href="#" title="header=[Au panier] body=[ ] fade=[on]"><img src= <?php echo $image;?>/shoppingcart.png alt="" title="" width="48" height="48" border="0" /></a></div>
</div>
<div class="title_box">Nouveaux</div>
<div class="border_box">
<div class="product_title"><a href="details.html">Motorola 156 MX-VL</a></div>
<div class="product_img"><a href="details.html"><img src= <?php echo $image?>/p2.gif alt="" title="" border="0" /></a></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="title_box">Logiciels</div>
<ul class="left_menu">
<li class="odd"><a href="services.html">Jeux</a></li>
<li class="even"><a href="services.html">Utilitaires</a></li>
<li class="odd"><a href="services.html">OS</a></li>
</ul>
<div class="banner_adds">
<a href="#"><img src=<?php echo $image?>/bann1.jpg alt="" title="" border="0" /></a>
</div>
La solution
Eh bien, pour rediriger vers un autre contrôleur, il vous suffit de mettre le chemin URL de ce contrôleur comme href de l'ancre.
<a href="/controller/action"></a>
Exemple de page de description de produit :
<a href="/products/item/324235">Product</a>
Où 324235 est un numéro de produit donné qui doit être injecté dans le href à partir du code côté serveur.
Désolé, je n'ai pas parcouru votre code, donc les noms de votre contrôleur et de votre action peuvent être différents.