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

后端 未结 13 2131
忘掉有多难
忘掉有多难 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_000000102.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 20:13</span> </div> </div> <div class="detail-body jieda-body photos"> <p> <p>Create a base controller. The default location for this is <code>application/core/MY_Controller.php =></code> this can be changed via the config. By using <code>$this->site_data</code> you can add variables in your base class and use them in every controlle/view</p> <pre><code>class MY_Controller extends CI_Controller { function __construct() { parent::__construct(); $this->load->database(); $this->load->model('your model'); $result = $this->Listing_model->get_card($card); $this->site_data['query']=$result; $this->site_data_header["page_title"] = $result['get the property you want'];//this is possible, as get_card returns 1 result } } class YourClass extends MY_Controller { function __construct() { parent::__construct(); } public function show($card = NULL) { //you don't need to split the variables //for header and the rest $this->load->view('includes/header',$this->site_data_header); $this->load->view('listings/listing_card',$this->site_data); $this->load->view('includes/footer'); } } </code></pre> <p>And I think your get_where is wrong:</p> <pre><code>$query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset); </code></pre> <p>your limit is 0</p> <pre><code>function get_card($card = FALSE) { $query = $this->db->get_where('creditcards', array('slug' => $card), 1,0);//limit 1 offset 0 return $query->result(); } </code></pre> <p>access the data in your view</p> <pre><code><title><?php echo (!isset($page_title) ? '' : $page_title) ?>

提交回复
热议问题