CodeIgniter Parent Объявить

Как я могу сказать этот код ниже в моей конструкции parent :: _, а затем вызвать его в отдельную дочернюю функцию?

      /*bootstrap classes*/
$pag_config ['full_tag_open'] = "<ul class='pagination'>" ;
$pag_config ['full_tag_close'] ="</ul>" ;
$pag_config ['num_tag_open'] = '<li>' ;
$pag_config ['num_tag_close'] = '</li>' ;
$pag_config ['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>" ;
$pag_config ['cur_tag_close'] = "<span class='sr-only'></span></a></li>" ;
$pag_config ['next_tag_open'] = "<li>" ;
$pag_config ['next_tagl_close'] = "</li>" ;
$pag_config ['prev_tag_open'] = "<li>" ;
$pag_config ['prev_tagl_close'] = "</li>" ;
$pag_config ['first_tag_open'] = "<li>" ;
$pag_config ['first_tagl_close'] = "</li>" ;
$pag_config ['last_tag_open'] = "<li>" ;
$pag_config ['last_tagl_close'] = "</li>" ;

0

Решение

использование $this чтобы получить доступ к переменным класса.

class YourClass extends CI_Controller {

function __construct() {
parent::__construct();

$this->pag_config = array();
$this->pag_config['full_tag_open'] = "<ul class='pagination'>" ;
$this->pag_config['full_tag_close'] ="</ul>" ;
$this->pag_config['num_tag_open'] = '<li>' ;
$this->pag_config['num_tag_close'] = '</li>' ;
$this->pag_config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>" ;
$this->pag_config['cur_tag_close'] = "<span class='sr-only'></span></a></li>" ;
$this->pag_config['next_tag_open'] = "<li>" ;
$this->pag_config['next_tagl_close'] = "</li>" ;
$this->pag_config['prev_tag_open'] = "<li>" ;
$this->pag_config['prev_tagl_close'] = "</li>" ;
$this->pag_config['first_tag_open'] = "<li>" ;
$this->pag_config['first_tagl_close'] = "</li>" ;
$this->pag_config['last_tag_open'] = "<li>" ;
$this->pag_config['last_tagl_close'] = "</li>" ;
}

function childFunction() {
echo $this->pag_config['full_tag_open'];
}

}

Приведенный выше пример больше похож на то, что вы просили, но я бы посоветовал определить его как свойство, потому что оно выглядит намного чище.

class YourClass extends CI_Controller {

private $pag_config = array (
/*bootstrap classes*/
'full_tag_open' => "<ul class='pagination'>" ,
'full_tag_close' => "</ul>" ,
'num_tag_open' => '<li>' ,
'num_tag_close' => '</li>' ,
'cur_tag_open' => "<li class='disabled'><li class='active'><a href='#'>" ,
'cur_tag_close' => "<span class='sr-only'></span></a></li>" ,
'next_tag_open' => "<li>" ,
'next_tagl_close' => "</li>" ,
'prev_tag_open' => "<li>" ,
'prev_tagl_close' => "</li>" ,
'first_tag_open' => "<li>" ,
'first_tagl_close' => "</li>" ,
'last_tag_open' => "<li>" ,
'last_tagl_close' => "</li>" ,
) ;

function childFunction() {
echo $this->pag_config['full_tag_open'];
}

}
1

Другие решения

внутри родительской конструкции:

     $this -> pag_config = array (
/*bootstrap classes*/
'full_tag_open' => "<ul class='pagination'>" ,
'full_tag_close' => "</ul>" ,
'num_tag_open' => '<li>' ,
'num_tag_close' => '</li>' ,
'cur_tag_open' => "<li class='disabled'><li class='active'><a href='#'>" ,
'cur_tag_close' => "<span class='sr-only'></span></a></li>" ,
'next_tag_open' => "<li>" ,
'next_tagl_close' => "</li>" ,
'prev_tag_open' => "<li>" ,
'prev_tagl_close' => "</li>" ,
'first_tag_open' => "<li>" ,
'first_tagl_close' => "</li>" ,
'last_tag_open' => "<li>" ,
'last_tagl_close' => "</li>" ,
) ;

Внутри дочерняя функция:

      $pag_config ['total_rows'] = count ($to_count) ;
$pag_config ['per_page'] = $to_show ;
$pag_config ['uri_segment'] = 3 ;
$pag_config ['base_url'] = base_url().'prcsys/overall' ;

$merge_paginate = array_merge($pag_config,$this -> pag_config);
$this -> pagination -> initialize ($merge_paginate) ;
0

По вопросам рекламы [email protected]