亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 codeigniter 中調用自定義幫助程序的自定義同級方法并使用數據庫

如何在 codeigniter 中調用自定義幫助程序的自定義同級方法并使用數據庫

PHP
函數式編程 2022-08-05 16:05:50
編輯<?php   defined('BASEPATH') OR exit('No direct script access allowed'); function getCrud($table_name, $subject){    $CI =& get_instance();    $CI->load->database();    $crud = new grocery_Crud();    $crud->set_table($table_name);    $crud->set_subject($subject);    $crud->unset_read();    $crud->unset_clone();    $crud->where(array($table_name.'.flag' => '1'));    $crud->callback_delete(function ($primary_key) use ($table_name) {        return $CI->db->update($table_name, array('flag'=>'0'), array('id'=>$primary_key));    });    return $crud;} function oneToMany($table_name, $subject, $rel_table,$field='name'){    $crud = getGrocreyCrud($table_name, $subject);    $crud->set_relation($rel_table.'_id', $rel_table, 'name', array('flag' => '1'));    $output = $crud->render();    return $output;}我無法使用ci get實例調用上述函數getCrud。還有其他方法嗎?返回 $CI->db->update($table_name, array('flag'=>'0'), array('id'=>$primary_key));當在控制器中使用這些代碼行時($CI將在控制器中$this),我可以將標志設置為0,但在助手中它不會發生
查看完整描述

3 回答

?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

 class Gc_script

    {

        public $CI;

        public function __construct()

        {

            $this->CI =& get_instance();

            $this->CI->config->item('base_url');

        }


        public function getGrocreyCrud($table_name, $read=null)

        {

            $crud = new grocery_Crud();

            $crud->set_table($table_name);

            $crud->set_subject(ucwords(str_replace('_', ' ', $table_name)));


            $crud->callback_delete(function ($primary_key) use ($table_name) {

                return  $this->CI->db->update($table_name, array('flag'=>'0'), array('id'=>$primary_key));

            });


            return $crud;

        }

   }


查看完整回答
反對 回復 2022-08-05
?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

可能以下應該工作


<?php 

defined('BASEPATH') OR exit('No direct script access allowed');



if(!function_exists('getCrud'))

{

    function getCrud($table_name, $subject)

    {

        // some code

    }

}


if(!function_exists('oneToMany'))

{

    function oneToMany()

    {

        $CI =&get_instance();


        $crud = getCrud($table_name, $subject);

        return $crud ;

    }

}


查看完整回答
反對 回復 2022-08-05
?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

<?php 

    defined('BASEPATH') OR exit('No direct script access allowed');



    function getCrud($table_name, $subject)

    {

          // some code

    }


     function oneToMany()

    {

        $CI =&get_instance();


        $crud = $CI->getCrud($table_name, $subject);

        return $crud ;

    }

試試這個


查看完整回答
反對 回復 2022-08-05
  • 3 回答
  • 0 關注
  • 141 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號