Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Mostrar los títulos de las páginas en función de las páginas dinámicamente en codeigniter php

Cómo mostrar títulos de página dinámicamente en función de las páginas mostradas.

Hola, tengo un sitio desarrollado en codeigniter php, pero el problema es que es necesario mostrar los títulos de las páginas de forma dinámica en función de las páginas. Estos títulos de las páginas deben obtenerse de la base de datos. ¿Alguien puede tener alguna idea de cómo hacerlo?

Controlador:

 public function index() { $config = array(); $config["base_url"] = base_url('testimonial/index'); $config['total_rows'] = $this->testimonial_model->record_count();//here we will count all the data from the table $config['per_page'] = 6;//number of data to be shown on single page $config['first_link'] = 'First'; $config['last_link'] = 'Last'; $this->pagination->initialize($config); $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; $data["records2"] = $this->testimonial_model->get_all_testimonials($config["per_page"], $page); $data['records7'] = $this->index_model->get_all_banners(); $data["links"] = $this->pagination->create_links();//create the link for pagination $data['mainpage'] = "testimonial"; $this->load->view('templates/template',$data); }

Modelo:

 function get_all_testimonials($limit, $start) { $this->db->limit($limit, $start); $this->db->select('T.*'); $this->db->from('testimonials AS T'); $this->db->where(array('T.status'=>1)); $q = $this->db->get(); if($q->num_rows()>0) { return $q->result(); } else { return false; } }

Vista:

 <div class="container"> <div class="row testimonialpage"> <div class="col-md-12 testimonialpage"> <div class="col-md-9 testimonials" > <div class="testimonialpagetext"> </div> <?php if(isset($records2) && is_array($records2)):?> <?php foreach ($records2 as $r):?> <div class="testimonial1"> <div class="testimonialtext1"> <?php echo $r->description;?> <ul class="founders"> <li class="founder"><?php echo $r->client_name;?></li> <li class="founder"><?php echo $r->founder;?></li> </ul> </div> </div> <?php endforeach ;endif;?> <div class="pagination"><?php echo $links; ?></div> </div> </div> </div>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Por ejemplo: Su URL es www.example.com/controller/register cuando obtiene el segmento uri (2) significa que obtendrá (registro). en base a esto puedes identificar que estás en la página de registro. ahora puede encontrar el título de la página de registro en su base de datos.

over 4 years ago · Santiago Trujillo Report

0

Cada vez que construyo una aplicación con Codeigniter, uso una Clase MY_Controller que extiende CI_Controller, dentro de la aplicación/núcleo como se muestra a continuación:

 class MY_Controller extends CI_Controller { protected $view_data; function __construct() { //...... } }

Cualquier controlador dentro de application/controllers extenderá MY_Controller en lugar de CI_Controller .

Ahora en el constructor de MY_Controller puedes hacer algo como:

 $page = $this->uri->segment(2); (2 or 3 or 4 etc, depends on your structure)

Cargue su modelo, ejecute su consulta y agregue el resultado en $this->view_data como:

 $pageTitle = $this->your_model->getPageTitle($page); $this->view_data['page_title'] = $pageTitle['page_title'];

Ejemplo de getPageTitle en su modelo:

 public function getPageTitle($page) { $qry = $this->db->select('page_title') ->from('pages') ->where('page', $page) ->get(); if ($qry->num_rows() > 0) return $qry->row_array(); return false; }

¡Cuidado con los nombres de muestra que di, deberías cambiarlos!

Para cargar su vista, pase la variable $this->view_data como parámetro y en su vista haga algo como

 <title><?= $page_title ?></title>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!