controller中的A函数,可以调用controller中的B函数么?
各位版友好!代码:
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
}
public function index()
{
// $this->load->view('index');
$this->load->view('home');
}
public function sinaWburl2ID($url) {
$surl= str62to10(substr($url,strlen($url)-4,4));
$surl= str62to10(substr($url,strlen($url)-8,4));
$surl= str62to10(substr($url,0,strlen($url)-8));
return $surl . $surl . $surl;
}
public function str62to10($str62){ //62进制到10进制
$strarry=str_split($str62);
$str=0;
for ($i =0; $i <strlen($str62);$i++) {
$vi=Pow(62, (strlen($str62) - $i - 1));
$str+=$vi*str62keys($strarry[$i]);
}
return $str;
}
public function str62keys($ks)//62进制字典
{
$str62keys = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9","a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z","A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
return array_search($ks,$str62keys);
}
public function getCommentByUrl()
{
$url=$this->input->post('iurl');
$id=sinaWburl2ID($url);
// $id=3386232065026453;
$data['mid']=$id;
$this->load->view('test',$data);
}
我的程序是部署在SAE上面的。
结果一直报错:
SAE_Fatal_error: Call to undefined functionsinaWburl2ID()
我的疑问是:难道controller中的方法,不能互相调用么? 当然不能啦,看看ci的运行原理吧 jeongee 发表于 2011-12-4 11:49 static/image/common/back.gif
当然不能啦,看看ci的运行原理吧
饿。。那你就告诉我,应该怎么做呢?
我现在自己的思路是:
另外写一个 WeiBoUtility类,包含了这几个函数。
然后在getCommentByUrl()函数中实例化这个类,再调用里面的函数,这样可以的吧? zhulicong 发表于 2011-12-4 11:53 static/image/common/back.gif
饿。。那你就告诉我,应该怎么做呢?
我现在自己的思路是:
另外写一个 WeiBoUtility类,包含了这几个 ...
这个思路可行 你直接写在model里不行吗?干嘛非的死缠在controller里 ╰↓①秒つ. 发表于 2011-12-4 13:11 static/image/common/back.gif
你直接写在model里不行吗?干嘛非的死缠在controller里
模型原来可以这么用啊?
我还以为模型只能用作与数据库打交道。。。 我勒个去,php调用类内部的方法要用 $this->sinaWburl2ID() 7楼正解,我测试是可以的。
public function index()
{
$this->zjm();
$this->load->view('welcome_message');
}
public function zjm($p1 = 'a', $p2 = 'b')
{
print_r($_GET);
echo "$p1<br />$p2";
echo "cc";
}
7楼正解,不过不建议controller里面互相调用,把要调用的放到model 层。方便别的方法来调用。 轻抚菊花笑不语,终于解开这个困扰了
页:
[1]
2