English 中文(简体)
协调图书馆类公共变量无效
原标题:Codeigniter library class public variables not working

这是我代码的片段:

<?php

if (!defined( BASEPATH )) {
exit( No direct script access allowed );
}

class sample{

function __construct() {
    $this->ci = & get_instance();
    }

public $name;
public $style;


function set_data($data)
{
    /* List of parameters that you can set */

    $this->name = (isset($data[ name ]) ? $data[ name ]:   ); // Set select name
    $this->style = (isset($data[ style ]) ? $data[ style ]:   ); // Set select style

}

function select_both_dropdown()
{
    $select =  <select name=" .$this->name. " class="chzn-select" style=" .$this->style. "> ;
    $select .=  <option value=""></option> ;
    $select .=  </select> ;
return $select;
}

主计长:

$data[ select ] = $this->sample->select_both_dropdown(array(
         name  =>  eventselect ,
         style  =>  min-width: 247px; 
    ));

How it is being loaded in controller: function _construct() { parent::_construct(); $this->load->library( tank_auth ); $this->load->library( sample ); }

当选中的屏幕上加载时, 没有填充任何内容 。 没有名称, 没有样式等 。 我做错了什么?

最佳回答

您需要正确引用它们;

在图书馆;

// as you have done
$this->select =  foo ;

在您的控制器中,它会类似 $This- gt; sample- gt; name $This- gt; sample- gt; 样式 $This- gt; sampple- gt; 样式

但当选的美元不是一个属性, 或被退回, 将无法撤销 。

UPDATE - based on comments controller;

$this->sample->set_data(array(
         name  =>  eventselect ,
         style  =>  min-width: 247px; 
    ));
$data[ select ] = $this->sample->select_both_dropdown();

a next upate : 更新 :

function select_both_dropdown($data)
{
    $this->set_data($data);
    $select =  <select name=" .$this->name. " class="chzn-select" style=" .$this->style. "> ;
    $select .=  <option value=""></option> ;
    $select .=  </select> ;
return $select;
}

然后,我将把成套数据()改为私人数据,而不是公共数据。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签