How to fetch title of an item from a database and send it to the header template in CodeIgniter

后端 未结 13 2132
忘掉有多难
忘掉有多难 2021-02-18 19:12

I am writing an application in CodeIgniter where I specify the </code> meta-tag on every page in every controller which I have managed to send to my header te <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5408099190056760" data-ad-slot="7305827575" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="fly-panel detail-box" id="flyReply"> <fieldset class="layui-elem-field layui-field-title" style="text-align: center;"> <legend>13条回答</legend> </fieldset> <ul class="jieda" id="jieda"> <li data-id="111" class="jieda-daan"> <a name="item-1111111111"></a> <div class="detail-about detail-about-reply"> <a class="fly-avatar" href=""> <img src="https://www.e-learn.cn/qa/data/avatar/000/00/01/small_000000127.jpg" alt=" 爱一瞬间的悲伤 "> </a> <div class="fly-detail-user"> <a href="" class="fly-link"> <cite> 爱一瞬间的悲伤</cite> </a> <span>(楼主)</span> </div> <div class="detail-hits"> <span>2021-02-18 19:55</span> </div> </div> <div class="detail-body jieda-body photos"> <p> <p>You may need to create some routes for your show function. Codeigniter URI Routing</p> <pre><code>$route['your_controller_name/show/(:any)'] = 'your_controller_name/show/$1'; </code></pre> <p>I am not sure if you have set up a htaccess for your main directory so you could remove the <code>index.php</code> from your url.</p> <p>Try this code below</p> <p><strong>Model:</strong></p> <pre><code><?php class Listing_model extends CI_Model { function get_card_title($card) { $this->db->where('slug', $card); $query = $this->db->get($this->db->dbprefix . 'creditcards'); if ($query->num_rows() > 0) { $row = $quer->row(); return $row->title; } else { return false; } } } </code></pre> <p><strong>Controller:</strong> <code>Your_controller_name.php</code></p> <pre><code><?php class Your_controller_name extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('listing_model'); } public function show($card) { $data['title'] = $this->listing_model->get_card_title($card); $this->load->view('includes/header', $data); $this->load->view('listings/listing_card', $data); $this->load->view('includes/footer'); } } </code></pre> <p><strong>View:</strong></p> <pre><code><head> <title><?php echo $title;?>

提交回复
热议问题